【发布时间】:2016-05-28 11:27:14
【问题描述】:
我正在尝试使用我的等高线/箭袋图绘制底图。我下面的代码没有错误,但图像显示不正确;只显示箭筒。有什么帮助吗?
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 维度的 lat/lon 的显式声明?
-
是的,文件中只有 1 个点。纬度 = 38.97 和经度 = -77.47 @daryl
标签: python matplotlib plot matplotlib-basemap