我已经创建了一个堆叠的条形图,显示了一段时间内两类对象之间出现的百分比。我已经做了一个可视化的展示,但我想删除类1的值为= 0的注释。
这是我目前所看到的
如果你注意到上面的图片,29和31 (x轴值) 0.00出现在xtick应该在的位置。我特别想删除这些注释。
这是我用来创建可视化的代码:
dat_grouped = dat.groupby(['Hours','Class'])['Amount'].sum()
ax_three = dat_grouped.groupby(level=0).apply(lambda x:round(100*x/x.sum(),3)).unstack().plot.bar(stacked=True)
for i in ax_three.patches:
width,height=i.get_width(),i.get_height()
x,y = i.get_xy()
horiz_offset=1
vert_offset=2
ax_three.legend(bbox_to_anchor=(horiz_offset,vert_offset))
ax_three.annotate('{:.2f} %'.format(height),(i.get_x()+.15*width,i.get_y()+.5*height),rotation=90)
发布于 2019-05-23 05:20:22
一种方法是向注释步骤添加一个条件:
if height > 0:
ax_three.annotate('{:.2f} %'.format(height),
(i.get_x()+.15*width,
i.get_y()+.5*height),
rotation=90)
附注:您是否尝试过折线图而不是条形图?使用一行显示随时间的变化对我来说更有意义,而且可能看起来不那么忙,但对此没有确切的答案。
https://stackoverflow.com/questions/56265099
复制相似问题