Matplotlib箭头图比例尺

8
2个回答

15

指定每个箭头的位置、向量和长度是过度说明箭图的方式。因此,你需要改变你正在绘制的数据。

如果你有矢量场 U 和 V(与你的示例中的 U 和 V 相同),你可以通过以下方法对它们进行归一化:

N = numpy.sqrt(U**2+V**2)  # there may be a faster numpy "normalize" function
U2, V2 = U/N, V/N

然后你可以应用任何你想要的缩放因子数组:

U2 *= F
V2 *= F

0
如果您想了解两个向量x和y的相对矢量大小,可以尝试使用这种非线性缩放:
L = np.sqrt(x**2 + y**2)
U = x / L 
V = y / L 
#If we just plotted U and V all the vectors would have the same length since 
#they've been normalized.

m = np.max(L)
alpha = .1 
#m is the largest vector, it will correspond to a vector with 
#magnitude alpha in the quiver plot

S=alpha /(1+np.log(m/L)) 

U1=S*U 

V1=S*V

plt.figure() 
Q = plt.quiver(x,y,U1,V1,scale = 1., units='width') 

qk = plt.quiverkey(Q, 0.9, 0.9, 2, r'$2 \frac{m}{s}$', 
labelpos ='E',coordinates='figure')

您可以通过增加或减少alpha的值来改变向量幅度的范围。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接