【问题标题】:Matplotlib don't show the correct vectorMatplotlib 不显示正确的向量
【发布时间】:2021-10-07 15:10:41
【问题描述】:

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

我的矢量图:

【问题讨论】:

    标签: python matplotlib plot vector visualization


    【解决方案1】:

    您还应该指定参数:

    • 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')
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-05-30
      • 2021-02-15
      • 2017-11-24
      • 1970-01-01
      • 2023-01-18
      • 2019-12-28
      • 2017-04-29
      相关资源
      最近更新 更多