简体   繁体   English

Seaborn 的问题,未在计数图中显示 Y 轴的值

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

I have the following dataframe ( ordered_recurrent_df ) which I wish to plot in Seaborn's countplot:我有以下 dataframe ( ordered_recurrent_df ) 我希望在 Seaborn 的计数图中 plot :

ordered_recurrent_df : ordered_recurrent_df

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

When I try plotting it using countplot, I get the following:当我尝试使用 countplot 绘制它时,我得到以下信息:

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

在此处输入图像描述

The same outcome occurs when I try transposing it, it seems to me is not taking into account the values from the " Card " column.当我尝试转置它时会发生相同的结果,在我看来,它似乎没有考虑“卡片”列中的值。 Like if it only recognizes the values as labels, but that's it.就像它只将值识别为标签一样,仅此而已。

Any help is appreciated Thanks in advance任何帮助表示赞赏提前谢谢

barplot should work in your case: 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())

NB I did set an index because in your countplot example you also used the month index.注意我确实设置了一个索引,因为在您的countplot示例中您还使用了month索引。

在此处输入图像描述

countplot can be used when your data looks like:当您的数据如下所示时,可以使用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