airbornegeo.nice_scalebar_width

airbornegeo.nice_scalebar_width#

nice_scalebar_width(map_width, target_fraction=0.1)[source]#

Round a fraction of the map width to a human-friendly scalebar length.

Returns the value of the form 1, 2, 2.5, 5 or 10 times a power of ten which is closest (in log space) to map_width * target_fraction, so the bar stays near the requested fraction of the map rather than always rounding up.

Parameters:
  • map_width (float) – Width of the map, in the same units as the coordinates (e.g. metres). Must be positive.

  • target_fraction (float) – Fraction of the map width the scalebar should span, by default 0.1. Must be greater than 0 and no greater than 1.

Returns:

A nicely rounded scalebar length, in the units of map_width.

Return type:

float

Examples

>>> nice_scalebar_width(1e6)
100000.0
>>> nice_scalebar_width(6e6)
500000.0