Skip to content

Instantly share code, notes, and snippets.

@nkrumm
Created June 11, 2013 23:58
Show Gist options
  • Save nkrumm/5761872 to your computer and use it in GitHub Desktop.
Save nkrumm/5761872 to your computer and use it in GitHub Desktop.
Handy function to label barplots
def autolabel(ax,rects,text,fmt=None,below=False,offset_fraction=0.05):
for rect,t in zip(rects,text):
height = rect.get_height()+rect.get_y()
if below:
ax.text(rect.get_x()+rect.get_width()/2., (1-offset_fraction)*height, t,
ha='center', va='top', **fmt)
else:
ax.text(rect.get_x()+rect.get_width()/2., (1+offset_fraction)*height, t,
ha='center', va='bottom', **fmt)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment