在matplotlib底图中使用scalebar

时间:2013-12-12 16:01:26

标签: matplotlib 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()

实际上,我不知道如何提供显示比例尺所需的lat,lon,lat0和lon0参数。如何提供?

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

中的教程

http://matplotlib.org/basemap/api/basemap_api.html将其描述如下:

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)

如果有人可以帮助我,我将不胜感激。

1 个答案:

答案 0 :(得分:5)

drawmapscale似乎不支持Basemapprojection='cyl'个实例(可能还有其他人;我只检查了projection='cyl'projection='moll'):< / p>

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)

这会导致以下错误:

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

drawmapscale似乎确实适用于其他预测。以Mollweide为例:

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

不幸的是,Basemap API似乎没有提到任何关于它不适用于所有预测的内容。但here似乎是一种潜在的解决方法。