我试图在美国地图上绘制500毫巴高度的等高线和500毫巴涡度值的填充等高线。h500
和vort
都是形状的二维阵列(7211440)
import numpy as np
import pygrib
import matplotlib.pyplot as plt
import cartopy.crs as ccrs
from cartopy.mpl.ticker
import LongitudeFormatter, LatitudeFormatter
from cartopy.util import add_cyclic_point
import cartopy.feature as cfeature
from datetime import datetime
date = datetime.today().strftime('%Y%m%d')
grib = 'gfs'+date+'.f012'
grbs=pygrib.open(grib)
grb = grbs.select(name='Geopotential Height')[0]
h500 = grb.values
grb1 = grbs.select(name='Absolute vorticity')[0]
vort = grb1.values
lats,lons = grb.latlons()
ax0 = plt.axes(projection=ccrs.PlateCarree())
height=ax0.contour(lons,lats,h500[:,:],levels=30,extend='both',
colors='black',transform=ccrs.PlateCarree())
vorticity = ax0.contourf(lons,lats,vort,levels=30,extend='both',
transform=ccrs.PlateCarree())
ax0.set_extent([230,300,20,70],ccrs.PlateCarree())
ax0.coastlines()
ax0.add_feature(cfeature.BORDERS)
ax0.add_feature(cfeature.STATES)
ax0.set_title('500mb(dam) Height & Absolute Vorticity(s-1)\n'+date+'valid 12Z')
plt.savefig(date+'12Z 500mbHeight_Vorticity_US.png')
plt.show()
当我使用ax0.contour
时,代码运行良好。当我尝试使用ax0.contourf
或plt.contourf
时,代码不会执行,它会超时,并且不会生成错误消息或任何回溯。我已经阅读了contourf的matplotlib文档,对我来说,没有明确的理由说明为什么代码不能正确运行
目前没有回答
相关问题 更多 >
编程相关推荐