在 Matplotlib 中設定繪圖畫布的大小


要設定 matplotlib 中繪圖畫布的大小,我們可以採取以下步驟

  • 設定圖形大小並調整子圖之間和周圍的邊距。使用 figsize 7.50 和 3.50 設定圖形大小。
  • 使用 numpy 建立 x 和 y 資料點。
  • 使用 plot() 方法繪製 x 和 y 資料點。
  • 要顯示圖形,請使用 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)
plt.show()

輸出

更新日期:02-6 月-2021

3 千次瀏覽

開始你的 職業

完成課程獲得認證

開始
廣告
© . All rights reserved.