3

I have the following matplotlib code:

ax = my_df.plot(x='arrival_month', y='my_count' ,kind='bar', figsize =  (20,10), fontsize = 16, color = 'b', alpha = 0.3)  
ax.set_xticklabels([t.get_text().split(" ")[0] for t in ax.get_xticklabels()])
ax.set_ylim([-50,300])
plt.show()

generates the figure:

enter image description here

I am wondering is it possible to add the count number on top of the bar like:

enter image description here

Thanks a lot!

Edamame
  • 23,718
  • 73
  • 186
  • 320

1 Answers1

2

Something like looping over

ax.annotate('(%s, %s)' % xy, xy=xy, textcoords='data')

should work, where xy are tuples representing the x- and y-value of each coordinate.

This has been suggested in an answer to another question.

If you give a MWE, we could also test our suggestions. Especially telling us what exactly my_df looks like, would help.

Community
  • 1
  • 1
Joooeey
  • 3,394
  • 1
  • 35
  • 49