箭袋风箭头对于比例=1来说太长并且与关键箭头不匹配

问题描述 投票:0回答:1

全部,

matplotlib quiver(风图)函数的参数scale=1会产生超出图形限制的长箭头。另一方面,使用scale=None似乎会产生逻辑箭头长度。对此有什么见解吗?

除了必须打印 None 的

print(ax_left.scale)
之外,如果仅在 IPython 控制台内执行,则会产生 127.27。有什么想法吗?

最后,考虑到 U=5,它应该与绘制的箭头 5 具有相同的恒定长度,令人惊讶的是,箭头键的长度与风箭头的长度并不完全匹配。

谢谢

enter image description here

import numpy as np
import matplotlib.pyplot as plt

x = np.linspace(0,200,9)
y = np.linspace(0,100,5)
X,Y = np.meshgrid(x,y)
U = 5*np.ones_like(X)
V = 5*np.ones_like(Y)

#%% understanding "scale"
plt.close('all')
fig, ax = plt.subplots(1,2)
ax_left=ax[0].quiver(x, y, U, V,scale=None)
ax[0].quiverkey(ax_left,X=0.8,Y=1.05,U=3.5,label='unit',labelpos='W')
ax[0].set_title('')
print('scale is '+str(ax_left.scale))

ax_right=ax[1].quiver(x, y, U, V,scale=1)
ax[0].quiverkey(ax_right,X=0.8,Y=1.05,U=3.5,label='unit',labelpos='W')
ax[1].set_title('')
print('scale is '+str(ax_right.scale))
plt.savefig('test.png')
python matplotlib ipython
1个回答
0
投票

根据scale_units部分下的

文档

要在 x-y 平面上绘制向量,其中 u 和 v 与 x 和 y 具有相同的单位,请使用

angles='xy'
scale_units='xy'
scale=1

我还调整了宽度,使箭头看起来更好。

import numpy as np
import matplotlib.pyplot as plt

plt.close("all")

x = np.linspace(0, 200, 9)
y = np.linspace(0, 100, 5)
X, Y = np.meshgrid(x, y)
U = 5*np.ones_like(X)
V = 5*np.ones_like(Y)

plt.close("all")
fig, ax = plt.subplots(figsize=(10,5))

ax_right = ax.quiver(X, Y, U, V, scale=1, scale_units="xy", angles="xy", width=4e-3)
ax.quiverkey(ax_right, X=0.8, Y=1.05, U=5, label="unit", labelpos="W")
print(f"scale is: {ax_right.scale}")

结果:

至于密钥,看起来是正确的。

© www.soinside.com 2019 - 2024. All rights reserved.