具有恒定箭头大小的Matplotlib颤动图 [英] Matplotlib quiver plotting with constant arrow size

查看:132
本文介绍了具有恒定箭头大小的Matplotlib颤动图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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.

谢谢

推荐答案

更改刻度对此无效.您需要对向量进行归一化,例如

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

这篇关于具有恒定箭头大小的Matplotlib颤动图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆