Matplotlib 不显示正确的矢量

Matplotlib don't show the correct vector

我是 python 的新手,正在学习使用 matplotlib 绘制图形。 我尝试绘制从 (0, 0)(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()

我的矢量图:

您还应指定参数:

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

阅读 documentation 了解有关这些参数的更多信息。

完整代码行:

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