增加 Matplotlib 中 X 軸標籤間距


要增加 Matplotlib 中 X 軸標籤的間距,我們可以在subplots_adjust()方法的引數中使用間距變數。

步驟

  • 設定圖形大小,並調整子圖之間以及周圍的填充。

  • 建立新圖形或者使用 figure() 方法啟用現有的圖形。

  • 使用 numpy 建立 x 和 y 資料點。

  • 使用 plot() 方法繪製 x 和 y。

  • 使用LaTex表示式,使用 xlabel() 方法放置xlabel

  • 使用 subplots_adjust() 方法增加或減少 X 軸標籤的間距

  • 要顯示圖形,請使用 show() 方法。

示例

import numpy as np
from matplotlib import pyplot as plt
plt.rcParams["figure.figsize"] = [7.50, 3.50]
plt.rcParams["figure.autolayout"] = True
fig = plt.figure()
x = np.linspace(-2, 2, 10)
y = np.exp(x)
plt.plot(x, y)
plt.xlabel("$\bf{y=e^{x}}$")
spacing = 0.100
fig.subplots_adjust(bottom=spacing)
plt.show()

輸出

更新時間: 01-Jun-2021

23K+ 瀏覽

開啟您的 職業生涯

完成課程即可獲得認證

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