Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

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

Any one knows how to do this ? Thank you

like image 636
Rhecsu Avatar asked Mar 30 '20 01:03

Rhecsu


People also ask

What is quiver3 Matlab?

quiver3( Z , U , V , W ) plots arrows with directional components specified by U , V , and W at equally spaced points along the surface Z . If Z is a vector, then the x-coordinates of the arrows range from 1 to the number of elements in Z and the y-coordinates are all 1.

What does PLT quiver do in Python?

The ax. quiver() method of matplotlib library of python provides an optional attribute color that specifies the color of the arrow. The quiver color attribute requires the dimensions the same as the position and direction arrays.


1 Answers

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:

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=(10,10))
v = np.random.uniform(low=-1, high=1, size=(10,10))
plt.quiver(xx, yy, u, v)

original

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)

enter image description here

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

like image 105
Derek Eden Avatar answered Oct 11 '22 10:10

Derek Eden