在 Matplotlib 中顯示繪圖前獲取空的刻度標籤


要在 matplotlib 中顯示繪圖前獲得空的刻度標籤,我們可以按以下步驟操作:

  • 建立一個數據點列表。

  • 使用 subplot() 方法向當前圖形新增子圖。

  • 使用 set_xticks() 方法和 set_xticklabels() 方法設定 刻度刻度標籤

  • 要獲得空的刻度標籤,可以使用 get_xticklabels(which='minor')

  • 要展示該方法,可以使用 show() 方法。

示例

from matplotlib import pyplot as plt
plt.rcParams["figure.figsize"] = [7.00, 3.50]
plt.rcParams["figure.autolayout"] = True
x = [1, 2, 3, 4]
ax1 = plt.subplot()
ax1.set_xticks(x)
ax1.set_xticklabels(["one", "two", "three", "four"])
print("Empty tick labels: ", ax1.get_xticklabels(which='minor'))
plt.show()

輸出

更新日期:15-5-2021

798 次瀏覽

開啟您的 職業生涯

透過完成課程獲得認證

開始
廣告
© . All rights reserved.