python - 使用 quiver() 绘制风矢量

标签 python matplotlib-basemap

我想绘制风矢量。我使用 basemap 和这个例子 http://basemaptutorial.readthedocs.org/en/latest/plotting_data.html#quiver 。 在我的文件中,经度从 0 到 360。我使用 latlon=True 将其转换为 -180:180。但是,当我使用“点”来定义点密度时,矢量仅绘制在我的图形的一半上。 这是代码: 当然,我使用这段代码:

m=Basemap(projection='cyl',llcrnrlat=30,urcrnrlat=80, llcrnrlon=-40,urcrnrlon=40,resolution='c')
latvar=nc.variables['lat']
lat=latvar[:]
lon=nc.variables['lon'][:]
X,Y=m(lon,lat)
lons,lats=meshgrid(lon,lat)
X4,Y4=m(lons,lats)
varU=ncU.variables['var1'][0,0,:,:]
varV=ncV.variables['var2'][0,0,:,:]
speed=np.sqrt(varUvarU+varVvarV)
yy=np.arange(0,len(Y[:]),3)
xx=np.arange(0,len(X[:]),3)
points=np.meshgrid(yy,xx)
m.quiver(X4[points],Y4[points],varU[points],varV[points],speed[points],cmap=cmap‌​,latlon=True)

有人可以帮我解决这个问题吗?谢谢。

最佳答案

你有很多事情正在发生,但我不确定你是否需要。我已经尝试过您的代码并进行了一些小的修改,并且它有效:

import numpy 
import matplotlib.pyplot as plt
from mpl_toolkits.basemap import Basemap

lon  =NC.variables['lon'][:]  
lat  =NC.variables['lat'][:]

m=Basemap(projection='cyl',,llcrnrlat=30,urcrnrlat=80, llcrnrlon=-40,urcrnrlon=40,resolution='c')

lons,lats=numpy.meshgrid(lon,lat)
X4,Y4=m(lons,lats)

varU=NC.variables['var1'][0,0,:,:]
varV=NC.variables['var2'][0,0,:,:]

speed=numpy.sqrt(varU*varU+varV*varV)

yy=numpy.arange(0,len(lat),3)
xx=numpy.arange(0,len(lon),3)

points=numpy.meshgrid(yy,xx)

m.quiver(X4[points],Y4[points],varU[points],varV[points],speed[points],cmap=cmap,latlon=True)
plt.show()

# with all points for comparison
m.quiver(X4,Y4,varU,varV,speed,cmap=cmap,latlon=True)
plt.show()

关于python - 使用 quiver() 绘制风矢量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32271278/

相关文章:

python - Heroku:找不到命令。在 Virtualenv 上工作

python - 使用 python basemap 和 pyproj 时出现运行时错误?

javascript - 基于 Leaflet 和 AngularJS 的 map 未正确加载

python - 根据 pandas 数据框中的条件,使用不同标记在 basemap 上绘制点

python - 使用 Python (matplotlib) 的自定义标记

python - 无法在 openpyxl 中导入工作簿

python - Pandas 的大小和计数有什么区别?

Python 函数装饰器之谜

python - Python 中的 H2OFrame() 正在向 Pandas DataFrame 添加额外的重复行 - Bug?

python - plt.savefig() : ValueError: All values in the dash list must be positive