我必须承认,我仍然无法理解绘图及其各部分与 matplotlib 的正确设置和关系,仍然令人困惑的是 Fig 与 plt 与 ax 是如何相互关联的,所以我只是进行了反复试验,文档有时更多让我感到困惑。 :-(
我正在从 json 绘制天气值并获得积分。我可以用下面的代码绘制,如下图所示
fig=plt.figure(figsize=(10,8))
ax=fig.add_subplot(1,1,1,projection=mapcrs)
ax.set_extent([-93,-86,13,19],datacrs)
ax.add_feature(cfeature.COASTLINE)
ax.add_feature(cfeature.BORDERS, linestyle=':')
ax.scatter(lon,lat,c=dat,transform=datacrs)
and I am able to plot the map
然后我使用 metpy 和这段代码生成插值
gridx, gridy, gridz = interpolate_to_grid(lon, lat, dat, interp_type='rbf', hres=.1, rbf_func='linear', rbf_smooth=0)
fig=plt.figure(figsize=(15,15))
ax=fig.add_subplot(1,1,1,projection=mapcrs)
#ax = fig.add_axes([0, 0, 1, 1], projection=mapcrs)
#ax.set_extent([-93,-86,13,19])
#ax.add_feature(cfeature.COASTLINE)
#ax.add_feature(cfeature.BORDERS, linestyle=':')
ax.contourf(gridx,gridy,gridz,levels=np.arange(10,60,2),cmap='viridis')
plt.plot(lon,lat,'k.',color='white')
我得到了所需的点插值,但无法显示特征,该怎么做?如果我取消注释 ax.extent,我看到的只是一个空的白色图形。如果我取消注释 ax.features,插值将显示为下图,但不是地图。
感谢您的帮助和指导。