我使用代码创建了一个绘图,结果如下所示:
代码:
%matplotlib inline
sns.histplot(x = 'time_class', hue = 'Det_poiResult',data = df, multiple="dodge", shrink=.8)
我想转换此图以显示结果的比例
我应该修改我的数据框来计算比例结果,然后绘制它,还是有任何简单的方法可以使用内置类来实现这一点
预期结果-1
on Y-axis I have proportions computed for each category of X instead of counts.
proportions computation:
for the blitz on X.
win= count(wins)/count(blitz)
loss= count(loss)/count(blitz)
draw= count(draw)/count(blitz)....
预期结果-2
on Y-axis I have proportions computed as a fraction of datapoints in the entire dataset instead of counts.
proportions computation:
for the blitz on X.
win= count(wins)/count(all datapoints of df)
loss= count(loss)/count(all datapoints of df)
draw= count(draw)/count(all datapoints of df)....
您可以使用pandas的groupby计算总和,并从中计算百分比。然后,
sns.barplot
可以创建绘图相关问题 更多 >
编程相关推荐