Home > Software engineering >  Quiver plot arrows using Matplotlib
Quiver plot arrows using Matplotlib

Time:07-02

I am trying to make a quiver plot using the list I4. In I4[0], (0,0) and (1,0) represent the starting position and the direction of the arrow respectively. However, the current output doesn't match the expected one. I attach both here.

import matplotlib.pyplot as plt
I4 = [[(0, 0), (1, 0)], [(0, 0), (0, -1)], [(1, 0), (1, -1)], [(0, -1), (1, -1)]]

fig, ax = plt.subplots(figsize = (10,10))
for i in range(0,len(I4)):
    ax.quiver(I4[i][0], I4[i][1])
plt.show()

The current output is

enter image description here

The expected output is

enter image description here

CodePudding user response:

Please, take a look at the documentation with help(ax.quiver): you'll see that you need to specify ax.quiver(x, y, u, v) where x, y are the starting coordinates, u, v represents the directions.

In practice, you need to unpack your lists, like this:

ax.quiver(*I4[i][0], *I4[i][1])

CodePudding user response:

Alternatively, you could use plt.arrow (doc enter image description here

  • Related