0
我想繪製輪廓/箭袋情節下的底圖。我的下面的代碼沒有提供任何錯誤,但圖像無法正確顯示;只顯示顫抖。任何幫助?輪廓/箭袋情節上的底圖疊加Python
import netCDF4
import numpy as np
import matplotlib
import matplotlib.pyplot as plt
import pylab
from mpl_toolkits.basemap import Basemap
ncfile = netCDF4.Dataset('30JUNE2012_0400UTC.cdf', 'r')
dbZ = ncfile.variables['MAXDBZF']
u = ncfile.variables['UNEW']
v = ncfile.variables['VNEW']
print u
print v
print dbZ
data = dbZ[0,0]
data.shape
print data.shape
z_index = 0 # z-level you want to plot (0-19)
U = u[0,z_index, :,:] #[time,z,x,y]
V = v[0,z_index, :,:]
map = Basemap(projection = 'merc',llcrnrlat=36,urcrnrlat=40,\
llcrnrlon=-80,urcrnrlon=-74,lat_ts=20,resolution='i')
x = np.arange(0,150)
y = np.arange(0,150)
X,Y = np.meshgrid(x,y)
lon, lat = map(X,Y, inverse = True)
levels = np.arange(5,60,3)
c = plt.contourf(lon,lat,data, levels, cmap='jet')
plt.colorbar()
plt.hold(True)
q=plt.quiver(U,V,width=0.002, scale_units='xy',scale=10)
qk= plt.quiverkey (q,0.95, 1.02, 20, '20m/s', labelpos='N')
plt.xlim([0,120])
plt.ylim([0,120])
plt.xlabel('X')
plt.ylabel('Y')
plt.title('Reflectivity and Dual-Doppler Winds at 1 KM', fontsize=12)
plt.show()
Here is my data structure:
<type 'netCDF4.Variable'>
float32 UNEW(time, z, y, x)
missing_value: -32768.0
unlimited dimensions: time
current shape = (1, 20, 150, 150)
filling off
<type 'netCDF4.Variable'>
float32 VNEW(time, z, y, x)
missing_value: -32768.0
unlimited dimensions: time
current shape = (1, 20, 150, 150)
filling off
<type 'netCDF4.Variable'>
float32 MAXDBZF(time, z, y, x)
missing_value: -32768.0
unlimited dimensions: time
current shape = (1, 20, 150, 150)
filling off
圖像看上去像:
在這裏你有一些混淆,經/緯度,您使用範圍0-150代表Y,其中在緯度範圍從-90到90的範圍內是沒有意義的。你的netCDF文件是否包含x和y維度的緯度/經度的顯式聲明? – daryl
是的,它只在文件中有1個點。 Lat = 38.97和Lon = -77.47daryl –