gpt4 book ai didi

python - Matplotlib 不显示正确的矢量

转载 作者:行者123 更新时间:2023-12-04 13:07:46 25 4
gpt4 key购买 nike

我是 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()

我的矢量图: my vector plot

最佳答案

您还应该指定参数:

  • 角度 = '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')

enter image description here

关于python - Matplotlib 不显示正确的矢量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/68618634/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com