如何在 Matplotlib 的子圖中降低刻度標籤的密度?
要降低 Matplotlib 中子圖中刻度標籤的密度,我們可以將最小值分配給密度。
步驟
初始化變數密度。
使用 numpy 建立 x 和 y 資料點。
使用 plot() 方法繪製 x 和 y 資料點。
使用 xticks() 方法獲取或設定 X 軸的當前刻度位置和標籤。
要顯示圖形,請使用show()方法。
示例
import numpy as np from matplotlib import pyplot as plt plt.rcParams["figure.figsize"] = [7.00, 3.50] plt.rcParams["figure.autolayout"] = True density = 10 x = np.linspace(-2, 2, density) y = np.sin(x) plt.plot(x, y) plt.xticks(x) plt.show()
輸出
廣告