如何在 Matplotlib 中將 xtick 標籤旋轉 90 度?


要將 xtick 標籤旋轉 90 度,我們可以採取以下步驟 −

  • 建立一個數字列表 (x)。

  • 向當前圖形新增一個子圖。

  • 設定 X 軸上的刻度。

  • 設定 xtick 標籤,並在該方法中使用 rotate=90 作為引數。

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

示例

import matplotlib.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"], rotation=90)
plt.show()

輸出

更新於: 2021 年 5 月 8 日

超過 8K 次觀看

開啟 職業生涯

透過完成課程獲得認證

入門
廣告
© . All rights reserved.