如何增加箭图的箭头大小,并改变尺度来描述震级而不是箭头?

2024-06-28 20:52:17 发布

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

我试图将WRF数据集可视化,以显示风速和方向。我用等高线和填充等高线来显示风速,用箭头来显示风向。我已经设法做到了,但是箭袋图上的箭头非常小,很难解释。所以我的第一个问题是,如何改变箭袋图中箭头的大小,使它们更清晰

Relevant quiver plot with small arrows

我的第二个问题也和上面贴的箭袋图有关。请注意,右侧的比例是从0到1.0。我不确定这是什么试图形象化。如果没有箭袋图,则显示风速的比例是正确的(见下图)

Wind speed with correct scale

如何获得正确的显示比例(图2中的比例),而不是图1中的比例?以下是相关代码:

# Get WRF variables
wind_10m = getvar(ds, 'uvmet10_wspd_wdir', units='ms-1')[0,:]
test_wind = getvar(ds, 'uvmet10_wspd_wdir', units='ms-1')
wspd_10m = getvar(ds, 'uvmet10', units='ms-1')
wrf_lat, wrf_lon = latlon_coords(wind_10m)
wrf_lons = to_np(wrf_lon)
wrf_lats = to_np(wrf_lat)
x = wrf_lon.values
y = wrf_lat.values
u_comp = wspd_10m[0,:,:]
v_comp = wspd_10m[1,:,:]
u = u_comp.values
v = v_comp.values

# Normalize u and v components for quiver plot
u_norm = u / np.sqrt(u**2 + v**2)
v_norm = v /np.sqrt(u**2 + v**2)

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

cart_proj = get_cartopy(wind_10m)
fig = plt.figure(figsize=(12,6))
ax = plt.axes(projection=cart_proj)
plt.contour(wrf_lons, wrf_lats, wind_10m, colors='black', transform=ccrs.PlateCarree())
plt.contourf(wrf_lons, wrf_lats, wind_10m, cmap=get_cmap('rainbow'), transform=ccrs.PlateCarree())
plt.quiver(x, y, u_norm, v_norm, pivot='middle', transform=ccrs.PlateCarree(), regrid_shape=50)

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: normtimenpplt箭头ax比例values