Reputation: 33
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 :
Upvotes: 3
Views: 257
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')
Upvotes: 4