Quiver matplotlib:具有相同大小的箭头
Quiver matplotlib : arrow with the same sizes
我想用箭袋做一个图,但我希望所有的箭头都具有相同的大小。
我使用以下输入:
q = ax0.quiver(x, y, dx, dy, units='xy' ,scale=1)
但即使添加像 norm = 'true' 或 Normalize = 'true' 这样的选项,箭头也不会被标准化
有人知道怎么做吗?谢谢
不确定是否可以通过向 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)
标准化图
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)
这只是通过矢量的大小对矢量的 u 和 v 分量进行归一化,从而保持正确的方向,但将每个箭头的大小缩小到 1
我想用箭袋做一个图,但我希望所有的箭头都具有相同的大小。
我使用以下输入:
q = ax0.quiver(x, y, dx, dy, units='xy' ,scale=1)
但即使添加像 norm = 'true' 或 Normalize = 'true' 这样的选项,箭头也不会被标准化
有人知道怎么做吗?谢谢
不确定是否可以通过向 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)
标准化图
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)
这只是通过矢量的大小对矢量的 u 和 v 分量进行归一化,从而保持正确的方向,但将每个箭头的大小缩小到 1