如何在 matplotlib 作圖時更改 x 刻度標記的字型大小?
若要更改 matplotlib 圖表 中xticks 的字型大小,我們可以使用fontsize 引數。
步驟
匯入 matplotlib 和 numpy。
設定圖形大小並調整子圖之間的邊距和周圍的邊距。
使用 numpy 建立 **x** 和 **y** 資料點。
使用 plot() 方法繪製 x 和 y 資料點。
使用 xticks() 方法設定 xticks 的字型大小。
若要顯示圖形,請使用 show() 方法。
示例
from matplotlib import pyplot as plt import numpy as np # Set the figure size plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True # x and y data points x = np.linspace(-5, 5, 100) y = np.sin(x) plt.plot(x, y) # Set the font size of xticks plt.xticks(fontsize=25) # Display the plot plt.show()
輸出
將生成以下輸出 -
廣告