Question

I wrote a script using Spyder IDE with mpl_toolkits basemap to plot a GPS track as arrows for direction colored by speed. Everything worked fine until I upgraded pandas to 0.13. The data is like this:

                            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)

Now when I try to run this line:

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)

I get this error:

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

If I remove the latlon=True arguement it runs but does not display the data. Any ideas what is wrong?

Was it helpful?

Solution

For whatever reason, Basemap.quiver doesn't like taking Pandas DataFrame columns after upgrading. I changed: gMap.quiver(AllPoints['lon'],AllPoints['lat']....) to: gMap.quiver(AllPoints['lon'].values,AllPoints['lat'].values....) and it works fine now.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top