Any ideas on how can I insert a scale bar in a map in matplotlib that shows the length scale? something like the one I have attached.
Or maybe any ideas on measuring and showing distances automatically (not drawing an arrow and writing the distance manually!)?
I would try the
matplotlib-scalebar
package. (For something like your example c.)Assuming you are plotting a map image with
imshow
or similar, and you know the pixel width/cell-size (the real-world equivalent size of one pixel on the map image), you can automatically create the scale bar:This example is straight off the PyPi matplotlib-scalebar package page but here it is for completeness:
There is a an already existing class for scalebars in matplotlib called AnchoredSizeBar. In the below example AnchoredSizeBar is used to add a scalebar to an image (or map over a 100x100 meter area of randomness).
Extent defines the images max and min of the horizontal and vertical values.
The four first arguments to AnchoredSizeBar are the transformation object of the coordinate system, scalebar length, label and location. Further optional arguments changes the layout. These are explained well in the docstring.
This gives Scalebar on an image / a map over a 100x100 meter area of random