Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

using scalebar in matplotlib basemap

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.

like image 392
2964502 Avatar asked Dec 12 '13 16:12

2964502


1 Answers

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.

like image 126
Spencer Hill Avatar answered Oct 20 '22 06:10

Spencer Hill