我已经花了几个小时来尝试自定义matplotlib.quiver
,但是一直没有成功。文档非常令人困惑,我无法解析如何设置每个参数。在我的轴中,一个垂直像素比一个水平像素的物理距离小得多,我希望quiver可以根据这个纵横比自动缩放箭头。使用以下代码时,我目前得到的是水平箭头:
Tlevs = np.arange(-1.,8.5,.5) + 0.
yy, zz = np.meshgrid(ds.YC, ds.Z)
fig, ax = plt.subplots(figsize=(8,5))
fig.set_tight_layout(True)
im = ax.contourf(T_clim.YC, T_clim.Z, T_clim, levels=Tlevs)
ax.quiver(yy[::3,::10], zz[::3,::10],
vpFep_b[::3,::10], wpFep_b[::3,::10],
pivot='mid', angles='xy', units='xy')
ax.set_xlabel('Y [m]', fontsize=13)
ax.set_ylabel('Depth [m]', fontsize=13)
cbar = fig.colorbar(im, ax=ax)
cbar.set_label(r"[$^\circ$C]")
将 quiver 选项设置为以下内容,只会显示箭头的点:
ax.quiver(yy[::3,::10], zz[::3,::10],
vpFep_b[::3,::10], wpFep_b[::3,::10],
pivot='mid', angles='xy', scale_units='xy', scales=1.)
并且:
ax.quiver(yy[::3,::10], zz[::3,::10],
vpFep_b[::3,::10], wpFep_b[::3,::10],
pivot='mid', angles='xy', scale_units='xy')
显示以下错误:
/home/takaya/miniconda3/envs/uptodate/lib/python3.6/site-packages/matplotlib/quiver.py:666: RuntimeWarning: divide by zero encountered in double_scalars
length = a * (widthu_per_lenu / (self.scale * self.width))
/home/takaya/miniconda3/envs/uptodate/lib/python3.6/site-packages/matplotlib/quiver.py:666: RuntimeWarning: invalid value encountered in multiply
length = a * (widthu_per_lenu / (self.scale * self.width))
/home/takaya/miniconda3/envs/uptodate/lib/python3.6/site-packages/matplotlib/quiver.py:719: RuntimeWarning: invalid value encountered in less
short = np.repeat(length < minsh, 8, axis=1)
/home/takaya/miniconda3/envs/uptodate/lib/python3.6/site-packages/matplotlib/quiver.py:733: RuntimeWarning: invalid value encountered in less
tooshort = length < self.minlength
非常感谢您的帮助。谢谢!