調整 Matplotlib 中繪圖邊緣與 X 軸之間的間距


要調整繪圖邊緣與 X 軸之間的間距,我們可以使用 tight_layout() 方法或設定當前圖形的底部填充。

  • 設定圖形大小並調整子圖之間的填充。
  • 使用 numpy 建立 x 和 y 資料點。
  • 使用 plot() 方法繪製 x 和 y 資料點。
  • 要顯示圖形,請使用 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(-2, 2, 100)
y = np.exp(x)
plt.plot(x, y, c='red', lw=1)
plt.show()

輸出

更新時間:2021-06-02

超過 3K 的瀏覽量

開啟你的職業生涯

完成課程獲得認證

開始
廣告
© . All rights reserved.