1
這是我第一次嘗試使用matplotlib繪圖。我試圖用matplotlib繪製位勢高度的netCDF文件數據,並得到一個空白圖像。沒有海岸線或任何東西。只是一個空白的屏幕。 我的數據範圍從5 N到40 N,從65 E到100 E.無法使用matplotlib顯示數據
我打印出lat,lon和hgt的值,它們都是有效的。
這裏是我的代碼 -
nc_f = './hgt_500_2014_12_5_00Z.nc' # Your filename
nc_fid = Dataset(nc_f, 'r') # Dataset is the class behavior to open the file
lats = nc_fid.variables['lat'][:]
lons = nc_fid.variables['lon'][:]
time = nc_fid.variables['time'][:]
hgt = nc_fid.variables['hgt'][:]
hgt_units = nc_fid.variables['hgt'].units
nc_fid.close()
lon_0 = lons.mean()
lat_0 = lats.mean()
m = Basemap(width=5000000,height=3500000,
resolution='l',projection='stere',\
lat_ts=40,lat_0=lat_0,lon_0=lon_0)
lon, lat = np.meshgrid(lons, lats)
xi, yi = m(lon, lat)
cs = m.pcolor(xi,yi,np.squeeze(hgt))
m.drawparallels(np.arange(5., 40., 5.), labels=[1,0,0,0], fontsize=10)
m.drawmeridians(np.arange(65., 100., 5.), labels=[0,0,0,1], fontsize=10)
m.drawcoastlines()
m.drawstates()
m.drawcountries()
cbar = m.colorbar(cs, location='bottom', pad="10%")
cbar.set_label(hgt_units)
plt.title('Geopotential Height')
plt.show()
當我運行python
Traceback (most recent call last):
File "/usr/local/lib/python3.4/dist-packages/matplotlib-1.5.0-py3.4-linux-x86_64.egg/matplotlib/backends/backend_gtk3agg.py", line 69, in on_draw_event
buf, cairo.FORMAT_ARGB32, width, height)
NotImplementedError: Surface.create_for_data: Not Implemented yet.
Traceback (most recent call last):
File "/usr/local/lib/python3.4/dist-packages/matplotlib-1.5.0-py3.4-linux-x86_64.egg/matplotlib/backends/backend_gtk3agg.py", line 69, in on_draw_event
buf, cairo.FORMAT_ARGB32, width, height)
NotImplementedError: Surface.create_for_data: Not Implemented yet.
100%正確的問題!我剛安裝了開羅,並得到它的工作!非常感謝 ! – gansub