旋轉 Matplotib 中 Seaborn 條形圖刻度標籤


為旋轉 Seaborn 條形圖的刻度標籤,我們可以採取以下步驟 -

  • 使用 Pandas 製作一個數據框。

  • 使用 Seaborn 的 barplot() 方法繪製條形圖。

  • xticks 標籤旋轉 45 度角。

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

示例

import pandas
import matplotlib.pylab as plt
import seaborn as sns
import numpy as np
plt.rcParams["figure.figsize"] = [7.50, 3.50]
plt.rcParams["figure.autolayout"] = True
df = pandas.DataFrame({"X-Axis": [np.random.randint(10) for i in range(10)], "YAxis": [i for i in range(10)]})
bar_plot = sns.barplot(x='X-Axis', y='Y-Axis', data=df)
plt.xticks(rotation=45)
plt.show()

輸出

更新於: 10-4-2021

7 千+ 瀏覽量

開啟你的事業

完成課程以獲得認證

開始
廣告
© . All rights reserved.