如何绘制 pandas.crosstab() 列
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/46541543/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to plot pandas.crosstab() columns
提问by Simone
I am trying to plot in the same figure the first nvalues which are the results of pd.crosstab()
, I have tried:
我试图在同一个图中绘制作为 的结果的前n 个值pd.crosstab()
,我尝试过:
tab = pd.crosstab(df['genre_ids'], df['target'],margins=True).sort_values('All',ascending=False)
tab = tab.drop('All',axis=1)
tab = tab.drop('All',axis=0)
tab[:top_n].plot(kind='bar', stacked=True)
plt.show()
but I get a barplotthat doesn't rappresent the actual values present in the tab's columns.
但我得到了一个条形图,它没有显示tab列中的实际值。
EDIT:
编辑:
This is the crosstab:
I would like plot the values in columns 0and 1, but I get this plot that it's different from the values in the columns:
Is it possible get something like this:
but with the 0and 1values plot in the same bar for each x-value?
这是交叉表:
我想绘制第0列和第1列中的值,但我得到这个图,它与列中的值不同:
是否有可能得到这样的东西:
但是在0和1值中绘制每个 x 值的条形相同?
回答by Simone
Solved simply set stacked = False
as has suggested @Nipun Batra in the comments.
stacked = False
按照评论中建议的@Nipun Batra简单设置即可解决。