Created
June 11, 2013 23:58
-
-
Save nkrumm/5761872 to your computer and use it in GitHub Desktop.
Handy function to label barplots
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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