sidescanpy.viz.scalebar#
A simple cartographic scale bar (line + end ticks + a rounded length
label), for any plot whose axes are already in real projected meters –
this library’s own default for sidescanpy.viz.track.plot_track_and_scanlines()
(auto-UTM) and sidescanpy.viz.gridded.plot_gridded_raster()
(auto-UTM-selected grid).
Deliberately not handling geographic (WGS84 degrees) axes automatically – meters-per-degree varies with latitude for the x-axis specifically, so a caller plotting directly in lat/lon would need to supply the real conversion factor at that plot’s own latitude, not something this function can infer from the axes alone.
2026 rshomberg@uri.edu
Contents
Draw a scale bar into |
- sidescanpy.viz.scalebar.add_scale_bar(ax, *, meters_per_data_unit=1.0, location='lower right', color='black', linewidth=3.0, fontsize=9, frac_of_width=0.2, margin=0.06)#
Draw a scale bar into
ax’s current view.Call this AFTER
ax’s final data/limits are set (e.g. after plotting and anyset_aspect/set_xlimcalls) – it readsax.get_xlim()to size itself to the current view, so calling it earlier would size it against limits that haven’t settled yet.- Parameters:
- meters_per_data_unitfloat, default 1.0
Real-world meters per one unit of
ax’s own x-axis data coordinates.1.0is correct for any plot already in projected meters (UTM northing/easting, this library’s own default for the track/gridded plots above) – pass a real computed value for anything else, never guess one.- location{“lower right”, “lower left”, “upper right”, “upper left”}
Corner to draw in, axes-fraction positioned (robust to whatever the current data range actually is).
- frac_of_widthfloat, default 0.2
Target length as a fraction of the axes’ current visible width, before rounding to a “nice” value – the actual drawn length is usually close to but not exactly this fraction.
- marginfloat, default 0.06
Axes-fraction margin from the plot edge.
Notes
Does nothing (not an error) if the axes’ current view is degenerate (zero or non-finite width), e.g. a single-point plot, where no scale bar length would be meaningful.