JTB
JTB

Reputation: 584

Strange Behavior in Pyplot Quiver Function

I have a very simple cell of code that draws a single vector with pyplot.quiver. It should start at (0,0) and stretch to (1,1). However, the arrow is clearly not directed to (1,1).

The documentation says that, with the call signature:

quiver([X, Y], U, V, [C], **kw)

X, Y define the arrow locations, U, V define the arrow directions, and C optionally sets the color.

What is happening here?

import numpy as np
import matplotlib.pyplot as plt

plt.quiver(0,0,1,1, scale=5)
plt.xlim(-2, 2)
plt.ylim(-2, 2)
plt.grid()
plt.show()

enter image description here

Upvotes: 1

Views: 387

Answers (1)

Zephyr
Zephyr

Reputation: 12524

Referring to the documentation, you should specify angles, scale_units and scale parameters in order to tell matplotlib you want to refer to (x, y) coordinates and units:

ax.quiver(0, 0, 1, 1, angles = 'xy', scale_units = 'xy', scale = 1)

enter image description here

Upvotes: 2

Related Questions