[英]How to improve this seaborn countplot?
您可以使用選擇x-axis
為垂直的示例,例如:
g = sns.countplot( x='Genres', data=gn_s)
g.set_xticklabels(g.get_xticklabels(),rotation=90)
或者,您也可以執行以下操作:
plt.xticks(rotation=90)
提前引入matplotlib來設置軸,以便您可以通過將軸刻度標簽旋轉90度和/或更改字體大小來修改軸刻度標簽。 為了按順序排列樣本,您需要修改源。 我假設您從熊貓數據幀開始,所以類似:
data = data.sort_values(by='Genres', ascending=False) labels = # list of labels in the correct order, probably your data.index fig, ax1 = plt.subplots(1,1) sns.countplot( x='Genres', data=gn_s, ax=ax1) ax1.set_xticklabels(labels, rotation=90)
可能會有所幫助。
編輯從評論中采納andrewnagyeb的建議以訂購劇情:
sns.countplot( x='Genres', data=gn_s, order = gn_s['Genres'].value_counts().index)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.