Kobbo
Kobbo

Reputation: 33

Matplotlib don't show the correct vector

I'm new to python and learn to plot graph with matplotlib. I try to plot vector that point from (0, 0) to (2, 1).

import matplotlib.pyplot as plt

O = [0, 0]
V = [2, 1]

plt.quiver(O[0], O[1], V[0], V[1], units='xy', scale=1, color='r')

plt.xlim(-3, 3)
plt.ylim(-3, 3)

plt.grid()
plt.show()

My vector plot : my vector plot

Upvotes: 3

Views: 257

Answers (1)

Zephyr
Zephyr

Reputation: 12496

You should specify also the parameters:

  • angles = 'xy'
  • scale_units = 'xy'

Read the documentation for more information on those parameters.

Full line of code:

plt.quiver(O[0], O[1], V[0], V[1], units = 'xy', angles = 'xy', scale = 1, scale_units = 'xy', color = 'r')

enter image description here

Upvotes: 4

Related Questions