2017-07-03 66 views
3

我一直在使用this后的代码行,以便在条形图中的列的顶部注释总值,但我似乎无法弄清楚如何在没有数字的情况下得到整数结果小数位?如何将大熊猫情节注释更改为整数?

ax = df.plot.bar(title="Scores") 
for p in ax.patches: 
    ax.annotate("%.2f" % p.get_height(), (p.get_x() + p.get_width()/2., p.get_height()), ha='center', va='center', xytext=(0, 10), textcoords='offset points') 

任何想法?

回答

4

数量只是转换为int

ax = df.plot.bar(title="Scores") 
for p in ax.patches: 
    ax.annotate(str(int(p.get_height())), (p.get_x() + p.get_width()/2., p.get_height()), ha='center', va='center', xytext=(0, 10), textcoords='offset points') 

演示: