Quiver matplotlib:具有相同大小的箭头

Rhe*_*csu 6 python matplotlib normalize

我正在尝试用箭袋绘制一个图,但我希望所有箭头都具有相同的大小。

我使用以下输入:

q = ax0.quiver(x, y, dx, dy, units='xy' ,scale=1) 
Run Code Online (Sandbox Code Playgroud)

但即使添加像norm ='true'或Normalize ='true'这样的选项,箭头也没有标准化

有人知道该怎么做吗?谢谢

Der*_*den 7

不确定是否有办法通过显式向 plt.quiver 提供 kwarg 来做到这一点,但快速解决方法如下:

原剧情

x = np.arange(10)
y = np.arange(10)
xx, yy = np.meshgrid(x,y)
u = np.random.uniform(low=-1, high=1, size=(10,10))
v = np.random.uniform(low=-1, high=1, size=(10,10))
plt.quiver(xx, yy, u, v)
Run Code Online (Sandbox Code Playgroud)

原来的

标准化图

r = np.power(np.add(np.power(u,2), np.power(v,2)),0.5) #could do (u**2+v**2)**0.5, other ways...
plt.quiver(xx, yy, u/r, v/r)
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述

这只是通过向量的大小标准化向量的 u 和 v 分量,从而保持正确的方向,但将每个箭头的大小缩小到 1