使用Python Basemap和Pyproj时出现运行时错误?
我用Spyder这个开发环境写了一个脚本,利用mpl_toolkits的basemap库来绘制GPS轨迹,箭头表示方向,颜色根据速度来区分。一切运行得很好,直到我把pandas升级到了0.13版本。
我的数据大概是这样的:
lon lat bearing speed m/s
2014-01-20 16:26:00 -170.681264 -14.290060 NaN NaN
2014-01-20 16:27:00 -170.681259 -14.290074 163.753636 0.026727
2014-01-20 16:28:00 -170.681259 -14.290074 180.000000 0.001172
2014-01-20 16:29:00 -170.681259 -14.290077 180.000000 0.004981
ll = [-14.294238,-170.683732]
ur = [-14.286362, -170.673260]
gMap = Basemap(projection='merc', resolution='f',
llcrnrlon=ll[1], llcrnrlat=ll[0],
urcrnrlon=ur[1], urcrnrlat=ur[0],ax=ax)
现在当我尝试运行这一行代码:
gMap.quiver(AllPoints['lon'],AllPoints['lat'],sin(radians(AllPoints['bearing'])),cos(radians(AllPoints['bearing'])),latlon=True,color=Points['speed m/s'].values,scale=40,cmap=plt.cm.rainbow)
我遇到了这个错误:
Traceback (most recent call last): File "", line 1, in File "C:\Python27\lib\site-packages\mpl_toolkits\basemap\__init__.py", line 559, in with_transform x, y = self(x,y) File "C:\Python27\lib\site-packages\mpl_toolkits\basemap\__init__.py", line 1148, in __call__ xout,yout = self.projtran(x,y,inverse=inverse) File "C:\Python27\lib\site-packages\mpl_toolkits\basemap\proj.py", line 286, in __call__ outx,outy = self._proj4(x, y, inverse=inverse) File "C:\Python27\lib\site-packages\mpl_toolkits\basemap\pyproj.py", line 388, in __call__ _proj.Proj._fwd(self, inx, iny, radians=radians, errcheck=errcheck) File "_proj.pyx", line 124, in _proj.Proj._fwd (src/_proj.c:1594) RuntimeError
如果我去掉latlon=True
这个参数,代码就能运行,但数据就不显示了。有没有人知道问题出在哪里?
1 个回答
9
不知道什么原因,Basemap.quiver在升级后不太喜欢直接用Pandas的DataFrame列。 我把代码从:gMap.quiver(AllPoints['lon'], AllPoints['lat']....) 改成了:gMap.quiver(AllPoints['lon'].values, AllPoints['lat'].values....) 现在一切都正常了。