能否給 Matplotlib 繪圖函式中的線設定邊框?


要在 matplotlib 繪圖函式中的線中設定邊框,我們可以呼叫 plot() 函式兩次,並使用不同的線寬。

步驟

  • 設定圖形大小並調整子圖之間和周圍的填充。
  • 使用 numpy 建立 x 和 y 資料點。
  • 繪製 x 和 y 資料點,其中 **線寬 = 10**,**顏色 = 黑色**.
  • 再次繪製 x 和 y 點,其中 **線寬 = 8**,**顏色 = 紅色**.
  • 使用 **show()** 方法顯示圖形。

例如

import numpy as np
from matplotlib import pyplot as plt
plt.rcParams["figure.figsize"] = [7.50, 3.50]
plt.rcParams["figure.autolayout"] = True
x = np.linspace(-2, 2, 100)
y = np.sin(x)
plt.plot(x, y, c='black', lw=10)
plt.plot(x, y, c='red', lw=8)
plt.show()

輸出

更新於:01-Jun-2021

1K+ 瀏覽

開啟你的 職業生涯

完成課程認證

開始
廣告
© . All rights reserved.