如何修复风倒钩,使其正确绘制?

2024-06-23 03:01:32 发布

您现在位置:Python中文网/ 问答频道 /正文

我一直在尝试在地图上绘制风倒钩,以便使用Python进行研究。在浏览了一些在线指南之后,我得出了这个结果,风倒钩在地图的中心绘制,而风倒钩应该在其坐标位置绘制(请参见图像链接)

Wind barb issues

我使用的数据来自WRF模型运行。下面是我的代码:

# Get WRF variables
wspd_10m = getvar(ds, 'wspd_wdir10', units='ms-1')[0,:]
u10 = getvar(ds, 'U10')
v10 = getvar(ds, 'V10')
wrf_lats, wrf_lons = latlon_coords(wspd_10m)
wrf_lons = to_np(wrf_lons)
wrf_lats = to_np(wrf_lats)
barb_lons, barb_lats = latlon_coords(u10)
barb_lons = to_np(barb_lons)
barb_lats = to_np(barb_lats)

# Timestamp
timestamp = to_np(wspd_10m.Time).astype('M8[s]').astype('O').isoformat()
time = wspd_10m.Time
time_str = str(time.values)

cart_proj = get_cartopy(wspd_10m)
fig = plt.figure(figsize=(12,6))
ax = plt.axes(projection=cart_proj)
plt.contour(wrf_lons, wrf_lats, wspd_10m, colors='black', transform=ccrs.PlateCarree())
plt.contourf(wrf_lons, wrf_lats, wspd_10m, cmap=get_cmap('rainbow'), transform=ccrs.PlateCarree())
plt.barbs(barb_lons[::50,::50], barb_lats[::50,::50], to_np(u10[::50,::50]), to_np(v10[::50,::50]), length=6)

plot_background(ax)

plt.colorbar(ax=ax, shrink=0.98)

ax.set_extent([-104.35, -94.45, 36.37, 44.78])
ax.set_title('10m Wind Speed and Direction (m/s) ' + time_str[:19])

plt.show()

Tags: totimenpds绘制pltaxstr

热门问题