簡體   English   中英

使用Seaborn barplot繪制大熊貓分類系列

[英]Plot a pandas categorical Series with Seaborn barplot

我想用seaborn繪制values_counts()方法的seaborn ,但是當我這樣做時,它僅顯示變量之一。

df = pd.DataFrame({"A":['b','b','a','c','c','c'],"B":['a','a','a','c','b','d']})
counts = df.A.value_counts()
sns.barplot(counts)

以上代碼的結果

我想要一個顯示高度為'a' = 1, 'b' = 2, 'c' = 3的條形圖

我嘗試重命名索引並傳遞xy參數,但無法使其正常工作。

你可以這樣做:

# Sorting indices so it's easier to read 
counts.sort_index(inplace=True)

sns.barplot(x = counts.index, y = counts)
plt.ylabel('counts')

在此處輸入圖片說明

請注意,使用pandas.Series.plot會給出非常相似的圖: counts.plot('bar')counts.plot.bar()

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM