Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 784
Kobbo Avatar asked Mar 10 '26 19:03

Kobbo


1 Answers

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

like image 118
Zephyr Avatar answered Mar 13 '26 20:03

Zephyr



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!