2016-06-24 68 views
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. 

回答

1
  1. 你可以寫,就像lons = nc_fid.variables['lon']我也得到這個錯誤。

  2. 檢查LAT-LON值他們必須支付你5 N到40 N和65電子商務區100 E.

  3. drawstates()不適合您所在的地區工作,該命令繪製州邊界我們。

  4. 檢查其他GUI後端:TkAgg,WX,QTAgg,QT4Agg像:

    import matplotlib

    matplotlib.use('Agg')

  5. 這可能是與開羅圖書館

+0

100%正確的問題!我剛安裝了開羅,並得到它的工作!非常感謝 ! – gansub