3

I've been using the line of code from this post in order to annotate total values on top of my columns in a bar plot, but I can't seem to figure out how to get the result in a whole number with no decimal places?

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')

Any ideas?

AGH_TORN
  • 813
  • 17
  • 33

1 Answers1

4

Just convert the number to an 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')

Demo:

Vinícius Figueiredo
  • 6,300
  • 3
  • 25
  • 44