如何在 Matplotlib 中绘制更多类型的线条?

pythonserver side programmingprogramming更新于 2025/8/8 17:16:17

要在 Matplotlib 中绘制更多类型的线条,我们可以采取以下步骤 −

  • 设置图形大小并调整子图之间和周围的填充。
  • 使用 numpy 创建 x 和 y 数据点。
  • 使用 plot() 方法绘制 x 和 y 数据点,带有一个虚线数组。
  • 要显示图形,请使用 show() 方法。

示例

from matplotlib import pyplot as plt
import numpy as np

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

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

plt.plot(x, y, dashes=[1, 1, 2, 1, 3], linewidth=7, color='red')

plt.show()

输出


相关文章


有用资源