使用 Matplotlib 旋轉 Seaborn 箱形圖中的 x 刻度標籤


要旋轉 Seaborn 箱形圖中的 x 刻度標籤,我們可以採取以下步驟:

  • xticks 建立資料點。

  • 使用返回軸的boxplot() 方法繪製箱形圖。

  • 現在,使用 set_xticks() 方法設定 x 刻度,傳遞 x 刻度。

  • 設定xticklabels並傳遞一個標籤列表,並使用 set_xticklabels() 方法透過傳遞rotation=45將其旋轉。

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

示例

import seaborn as sns
from matplotlib import pyplot as plt
plt.rcParams["figure.figsize"] = [7.00, 3.50]
plt.rcParams["figure.autolayout"] = True
xticks = [1, 4, 5, 2, 3]
ax = sns.boxplot(xticks)
ax.set_xticks(xticks)
ax.set_xticklabels(["one", "two", "three", "four", "five"], rotation=45)
plt.show()

輸出

更新於: 2021 年 05 月 06 日

10K+ 檢視

開啟您的職業生涯

完成課程後獲得認證

開始
廣告
© . All rights reserved.