9
from mpl_toolkits.basemap import Basemap
import matplotlib.pyplot as plt
import numpy as np

m = Basemap(projection='cyl',resolution='c',area_thresh=10,llcrnrlon=-180,urcrnrlon=180,\
    llcrnrlat=-90,urcrnrlat=90)
m.etopo()

Actually, I did not know how to provide the lat, lon, lat0, and lon0 parameters required to show scale-bar. How to provide them?

map.drawmapscale(????,barstyle='simple',units='km',fontsize=9,labelstyle='simple',fontcolor='k')

The tutorial at

http://matplotlib.org/basemap/api/basemap_api.html describe it as follows:

drawmapscale(lon, lat, lon0, lat0, length, barstyle='simple', units='km', fontsize=9, yoffset=None, labelstyle='simple', fontcolor='k', fillcolor1='w', fillcolor2='k', ax=None, format='%d', zorder=None)

Would appreciate if someone could help me.

3
  • 2
    If you would provide the right values you will run into: ValueError: cannot draw map scale for projection='cyl'. You cant make a scale in kilometers for a map in degrees, the length of a km is different at every location. Commented Dec 13, 2013 at 7:48
  • @ Rutger Kassies ok then can you show me an example of drawing scalebar using degree as the unit? Commented Dec 16, 2013 at 17:47
  • 1
    Adding gridlines via drawmeridians and drawparallels will likely be more helpful than a scale bar for degrees. Commented Dec 22, 2013 at 23:14

1 Answer 1

6
+50

It appears that drawmapscale doesn't support Basemap instances with projection='cyl' (and possibly others; I have only checked projection='cyl' and projection='moll'):

In [7]: m = Basemap(projection='cyl',resolution='c',area_thresh=10,llcrnrlon=-180,\
                    urcrnrlon=180, llcrnrlat=-90,urcrnrlat=90)

In [8]: m.etopo()
Out[8]: <matplotlib.image.AxesImage at 0x10a899e90>

In [10]: m.drawmapscale(50, -75, 0, 0, 400)

This results in the following error:

ValueError: cannot draw map scale for projection='cyl'

But drawmapscale does appear to work for other projections. Using Mollweide, for example:

In [11]: m = Basemap(projection='moll', lon_0=0)
In [12]: m.etopo()
Out[12]: <matplotlib.image.AxesImage at 0x10c299450>

In [13]: m.drawmapscale(50, -75, 0, 0, 400)
Out[13]: 
[<matplotlib.lines.Line2D at 0x11d2e41d0>,
 <matplotlib.lines.Line2D at 0x109cd4d90>,
 <matplotlib.lines.Line2D at 0x11d2e4750>,
 <matplotlib.text.Text at 0x11d2e4d90>,
 <matplotlib.text.Text at 0x11d2e5610>]

enter image description here

Unfortunately the Basemap API doesn't seem to mention anything about it not working for all projections. But here seems to be a potential workaround.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.