How does Python matplotlib.pyplot.quiver work?

I am trying to understand how the quiver function works in the NumPy module. Presumably, this allows you to graphically visualize the values ​​of two arrays, for example, horizontal and vertical speeds. I have the following very simple example, but I'm showing it to see if you can help me figure out what I can’t do:

x = np.linspace(0,1,11)
y = np.linspace(1,0,11)
u = v = np.zeros((11,11))
u[5,5] = 0.2

plt.quiver(x, y, u, v)

The code gives the following figure:

http://imgur.com/Rg3ZoHl

As you can see, an arrow is not an arrow, but a line, and it is longer than 0.2. I'm going to get an arrow of 0.2 length, and I thought I could do it using quiver. Is it possible? Or am I better off using a different command?

+10
3

matplotlib . 1, 0,2 x y:

x = np.linspace(0,1,11)
y = np.linspace(1,0,11)
u = v = np.zeros((11,11))
u[5,5] = 0.2

plt.quiver(x, y, u, v, scale=1)

enter image description here

scale, matplotlib , . , . .

x y , :

x = np.linspace(0,1,11)
y = np.linspace(1,0,11)
u = v = np.zeros((11,11))
u[5,5] = 0.2

plt.axis('equal')
plt.quiver(x, y, u, v, scale=1, units='xy')

, xy.

enter image description here

+15

, : , , u[5, 5] = 0.2, v[5, 5] = 0.2 ( ), , u = v = np.zeros((11, 11)). ,

u = np.zeros((11, 11))
v = np.zeros((11, 11))

u v .

+3

, :

example quiver plot

( ). . , , .

, () (, , ). ; , ! , - , .

In other words, you should not expect that the value of the field 0.2 will be represented by an arrow 0.2 in length in data units.

However, matplotlib provides an option that you can specify for this: an option scale_unitsfor quiver. According to the documentation, you can specify scale_units = 'xy', and it will display the lengths of the arrows using the same units as the axes.

+1
source

Source: https://habr.com/ru/post/1620915/


All Articles