gpt4 book ai didi

python - Matplotlib 箭袋绘图,箭头大小不变

转载 作者:太空宇宙 更新时间:2023-11-04 02:47:17 28 4
gpt4 key购买 nike

我正在尝试绘制一个简单的箭袋图(例如,在 matplotlib 库中:http://matplotlib.org/examples/pylab_examples/quiver_demo.html),尽管我不想启用自动缩放功能。

我只想显示场方向,而不是幅度。

有没有办法将箭头大小设置为常量?我尝试使用 scale 和 scale units 但这似乎只是通过一些共同因素改变了所有箭头。

谢谢

最佳答案

更改比例对此不起作用。您需要规范化向量,例如

X, Y = np.meshgrid(np.arange(0, 2 * np.pi, .2), np.arange(0, 2 * np.pi, .2))
U = np.cos(X)
V = np.sin(Y)

# Normalize the arrows:
U = U / np.sqrt(U**2 + V**2);
V = V / np.sqrt(U**2 + V**2);


plt.figure()
plt.title('Normalized arrows')
Q = plt.quiver(X, Y, U, V, units='width')
qk = plt.quiverkey(Q, 0.9, 0.9, 2, r'$2 \frac{m}{s}$', labelpos='E',
coordinates='figure')

关于python - Matplotlib 箭袋绘图,箭头大小不变,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44780933/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com