Contour不会绘制Python底图

时间:2015-10-25 19:01:28

标签: python numpy matplotlib matplotlib-basemap

我正在尝试在底图上绘制轮廓和箭头图。当我绘制时,我没有错误,但只显示底图。 netcdf文件只有一个点用于lat和long,所以我必须创建一个坐标范围。任何想法为什么会发生这种情况?

import netCDF4
import numpy as np
import matplotlib
import matplotlib.pyplot as plt
import pylab
from mpl_toolkits.basemap import Basemap
from matplotlib.patches import Polygon

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, :,:]

lats = np.linspace(35.0, 41.0, data.shape[0])
lons = np.linspace(-81.0,-73.0, data.shape[1])




# create the map

map = Basemap(llcrnrlat=36,urcrnrlat=40,\
 llcrnrlon=-80,urcrnrlon=-74,lat_ts=20,resolution='c')
# load the shapefile, use the name 'states'
map.readshapefile('st99_d00', name='states', drawbounds=True)

# collect the state names from the shapefile attributes so we can
# look up the shape obect for a state by it's name
state_names = []
for shape_dict in map.states_info:
    state_names.append(shape_dict['NAME'])

ax = plt.gca() # get current axes instance




x,y = map(*np.meshgrid(lats,lons))


levels = np.arange(5,60,3)
c = map.contourf(x,y,data, levels, cmap='jet')
plt.colorbar()
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.show()

0 个答案:

没有答案