简体   繁体   English

Quiver matplotlib:具有相同尺寸的箭头

[英]Quiver matplotlib : arrow with the same sizes

I'm trying to do a plot with quiver but I would like the arrows to all have the same size.我正在尝试使用 quiver 绘制一个图,但我希望所有箭头都具有相同的大小。

I use the following input :我使用以下输入:

q = ax0.quiver(x, y, dx, dy, units='xy' ,scale=1) 

But even if add options like norm = 'true' or Normalize = 'true' the arrows are not normalized但即使添加诸如 norm = 'true' 或 Normalize = 'true' 之类的选项,箭头也不会标准化

Any one knows how to do this ?任何人都知道如何做到这一点? Thank you谢谢

Not sure if there is a way to do this by explicitly providing a kwarg to plt.quiver, but a quick work around would be like this:不确定是否有办法通过向 plt.quiver 显式提供 kwarg 来做到这一点,但快速解决方法如下:

original plot原图

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

原来的

normalized plot归一化图

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)

在此处输入图片说明

this just normalizes the u and v components of the vector by the magnitude of the vector, thereby maintaining the proper direction, but scaling down the magnitude of each arrow to 1这只是通过矢量的幅度对矢量的 u 和 v 分量进行归一化,从而保持正确的方向,但将每个箭头的幅度缩小到 1

没有足够的声誉来评论@Derek 的帖子,但是可以通过说明代码的目的来更清楚地写出这一点 -将向量除以幅度以到达方向

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM