1

当我想在具有不规则分布的模型数据(来自 WRF-NMM)的地图上使用 matplotlib 绘制流线时遇到了一个奇怪的问题。

一开始,我定义了一个新的地图网格:

    # Define grid and create map grid
    lat = ga.expr('lat') #Latitude from GRIB-File (WRF-NMM), irregularly spaced
    lon = ga.expr('lon') #Longitude from GRIB-File (WRF-NMM), irregularly spaced
    U10 = ga.expr('ugrd10m')
    V10 = ga.expr('vgrd10m')

    map = Basemap(projection='cass', lat_0 = 47, lon_0 = 8,
                  resolution = 'c', llcrnrlon=5.8, llcrnrlat=45.6, 
                  urcrnrlon=10.9, urcrnrlat=48.0,)

    longitudes = lon[1,:]
    latitudes = lat[:,1]
    mx,my = np.meshgrid(longitudes,latitudes)
    mapx,mapy = map(mx,my)

    # Plot streamlines
    stream = map.streamplot(mapx,mapy,U10,V10, density=[0.5, 1])

不幸的是,上面的代码失败了,我自己也找不到错误。这个错误是来自奇怪的网格吗?

以下是错误消息:

/usr/local/lib/python2.7/dist-packages/matplotlib-1.3.1-py2.7-linux-x86_64.egg/matplotlib/contour.py:376: RuntimeWarning: invalid value encountered in true_divide
  dist = np.add.reduce(([(abs(s)[i] / L[i]) for i in range(xsize)]), -1)
Traceback (most recent call last):
  File "plot_map_v2.py", line 96, in <module>
    stream = map.streamplot(mapx,mapy,U10,V10, density=[0.5, 1])
  File "/usr/local/lib/python2.7/dist-packages/mpl_toolkits/basemap/__init__.py", line     551, in with_transform
    return plotfunc(self,x,y,u,v,*args,**kwargs)
  File "/usr/local/lib/python2.7/dist-packages/mpl_toolkits/basemap/__init__.py", line 3691, in streamplot
    ret =  ax.streamplot(x,y,u,v,*args,**kwargs)
  File "/usr/local/lib/python2.7/dist-packages/matplotlib-1.3.1-py2.7-linux-x86_64.egg/matplotlib/axes.py", line 6861, in streamplot
transform=transform)
  File "/usr/local/lib/python2.7/dist-packages/matplotlib-1.3.1-py2.7-linux-x86_64.egg/matplotlib/streamplot.py", line 67, in streamplot
grid = Grid(x, y)
  File "/usr/local/lib/python2.7/dist-packages/matplotlib-1.3.1-py2.7-linux-x86_64.egg/matplotlib/streamplot.py", line 256, in __init__
assert np.allclose(x_row, x)
AssertionError
Error in atexit._run_exitfuncs:
Traceback (most recent call last):
  File "/usr/lib/python2.7/atexit.py", line 24, in _run_exitfuncs
func(*targs, **kargs)
  File "/usr/local/lib/python2.7/dist-packages/matplotlib-1.3.1-py2.7-linux-x86_64.egg/matplotlib/_pylab_helpers.py", line 86, in destroy_all
manager.destroy()
  File "/usr/local/lib/python2.7/dist-packages/matplotlib-1.3.1-py2.7-linux-x86_64.egg/matplotlib/backends/backend_gtk3.py", line 427, in destroy
self.canvas.destroy()
AttributeError: FigureManagerGTK3Agg instance has no attribute 'canvas'
Error in sys.exitfunc:
Traceback (most recent call last):
  File "/usr/lib/python2.7/atexit.py", line 24, in _run_exitfuncs
func(*targs, **kargs)
  File "/usr/local/lib/python2.7/dist-packages/matplotlib-1.3.1-py2.7-linux-x86_64.egg/matplotlib/_pylab_helpers.py", line 86, in destroy_all
manager.destroy()
  File "/usr/local/lib/python2.7/dist-packages/matplotlib-1.3.1-py2.7-linux-x86_64.egg/matplotlib/backends/backend_gtk3.py", line 427, in destroy
self.canvas.destroy()
AttributeError: FigureManagerGTK3Agg instance has no attribute 'canvas'

干杯,

马丁

4

1 回答 1

-1

看看这个页面以获得更好的想法来绘制数据:

http://matplotlib.org/basemap/users/examples.html

于 2014-06-03T17:46:03.373 回答