我一直在使用 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')
有什么想法吗?
最佳答案
只需将数字转换为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')
演示:
关于python - 如何将 Pandas 绘图注释更改为整数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44893942/