簡體   English   中英

Seaborn 的問題,未在計數圖中顯示 Y 軸的值

[英]Issue with Seaborn, not showing the values for Y axis in countplot

我有以下 dataframe ( ordered_recurrent_df ) 我希望在 Seaborn 的計數圖中 plot :

ordered_recurrent_df

Month   Card
January     4
February    7
March      11
April      32
May        96
June      704

當我嘗試使用 countplot 繪制它時,我得到以下信息:

sns.countplot(data = ordered_recurrent_df, x = ordered_recurrent_df.index)

在此處輸入圖像描述

當我嘗試轉置它時會發生相同的結果,在我看來,它似乎沒有考慮“卡片”列中的值。 就像它只將值識別為標簽一樣,僅此而已。

任何幫助表示贊賞提前謝謝

barplot應該適用於您的情況:

ordered_recurrent_df = pd.DataFrame(
    {'Month':['January','February','March', 'April', 'May', 'June'], 
     'Card':[4, 7, 11, 32, 96, 704]
    }
).set_index('Month')

sns.barplot(x='Month', y='Card', data=ordered_recurrent_df.reset_index())

注意我確實設置了一個索引,因為在您的countplot示例中您還使用了month索引。

在此處輸入圖像描述

當您的數據如下所示時,可以使用countplot

ordered_recurrent_df = pd.DataFrame(
    {'Month':['January','February','March', 'April', 'May', 'June'], 
     'Card':[range(4), range(7), range(11), range(32), range(96), range(704)]
    }
).set_index('Month').explode('Card')

sns.countplot(data = ordered_recurrent_df, x = ordered_recurrent_df.index)

暫無
暫無

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

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