如何用 Matplotlib 繪製更多型別的線條?


如要使用 Matplotlib 繪製更多型別的線條,可執行以下步驟:

  • 設定圖形大小,並調整子圖之間的填充。
  • 使用 numpy 建立 xy 資料點。
  • 使用 plot() 方法和一系列破折號繪製 xy 資料點。
  • 使用 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()

輸出

更新日期:2021 年 7 月 8 日

76 次瀏覽

開啟你的 事業

完成課程,獲得認證

開始學習
廣告
© . All rights reserved.