Matplotlib quiver plotting with constant arrow size

社会主义新天地 提交于 2019-12-29 09:01:31

问题


I'm trying to plot a simple quiver plot (e.g. as in the matplotlib gallery: http://matplotlib.org/examples/pylab_examples/quiver_demo.html), although I don't want the autoscaling feature enabled.

I only want to show the field direction, not the magnitude.

Is there a way to set the arrow size as constant please? I tried playing with the scale and scale units but this just seems to change all arrows by some common factor.

Thanks


回答1:


Changing scale won't work for this. You need to normalize the vectors, e.g.

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')


来源:https://stackoverflow.com/questions/44780933/matplotlib-quiver-plotting-with-constant-arrow-size

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!