如何使用 Matplotlib 在 Python 中绘制矢量?


使用 matplotlib 在 Python 中绘制矢量,我们可以执行以下步骤:

  • 创建 2×3 维度的矩阵。

  • 创建原点,作为向量的起点。

  • 使用**quiver() **方法绘制 3D 箭头字段,其中包括 **origin、data、colors**和 **scale=15**。

示例

import numpy as np
from matplotlib import pyplot as plt
plt.rcParams["figure.figsize"] = [7.00, 3.50]
plt.rcParams["figure.autolayout"] = True
data = np.array([[2, 1], [-1, 2], [4, -1]])
origin = np.array([[0, 0, 0], [0, 0, 0]])
plt.quiver(*origin, data[:, 0], data[:, 1], color=['black', 'red', 'green'], scale=15)
plt.show()

输出

更新于:08-May-2021

7K+ 浏览量

开启您的 职业生涯

完成课程获得认证

开始
广告
© . All rights reserved.