如何在 Matplotlib 中指定箭头形状的线条样式?


若要在 matplotlib 中绘制箭头形状的线条样式,我们可以使用 quiver() 方法。

步骤

  • 设置图形尺寸并调整子图之间和周围的边距。

  • 使用 numpy 创建 x 和 y 数据点。

  • 使用 quiver() 方法绘制线条。

  • 若要显示图形,请使用 show() 方法。

示例

import numpy as np
import matplotlib.pyplot as plt

plt.rcParams["figure.figsize"] = [7.50, 3.50]
plt.rcParams["figure.autolayout"] = True

x = np.linspace(-5, 5, 100)
y = np.sin(x)

plt.quiver(x[:-1], y[:-1], x[1:]-x[:-1], y[1:]-y[:-1], scale_units='xy', angles='xy', scale=1, color='red')

plt.show()

输出

更新时间:2021 年 6 月 4 日

847 次浏览

启动您的 职业生涯

完成课程以获得认证

开始
广告
© . All rights reserved.