Why does matplotlib's quiver transpose matrices before drawing?

Viewed 39

I'm trying to use quiver and I am struggling to understand how quiver is interpreting the input arrays U, V in its documentation https://matplotlib.org/3.5.0/api/_as_gen/matplotlib.pyplot.quiver.html

With the following code I expect the bottom-right arrow (element [2,0]) to point to the left. However, it's the top-left as in the attached figure.

import numpy as np
import matplotlib.pyplot as plt

x = np.linspace(0.3,.9,3)
y = x

nb_points = x.size
X,Y = np.meshgrid(x,y)

U = np.ones((nb_points, nb_points))
V = np.ones((nb_points, nb_points))
U[2,0] = -3
M = (np.hypot(U, V))   

fig,ax = plt.subplots(1,1, figsize=(4,4))
ax.quiver(X, Y, U, V, M, units='width', pivot='middle')
ax.set_xlim(.2,1)
ax.set_ylim(.2,1)

enter image description here

Can anyone explain what's going on?

1 Answers

I completely misinterpreted the meaning of U,V's indeces

U[2,0] is supposed to be interpreted as the direction of X[2,0],Y[2,0] = (.3,.9), which is the top-left point

Related