Last active
August 29, 2015 14:00
-
-
Save brianckeegan/11098328 to your computer and use it in GitHub Desktop.
Put labels inside barcharts.
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
# adapted from http://matplotlib.org/examples/api/barchart_demo.html | |
def autolabel(rects): | |
max_height = max([rect.get_height() for rect in rects if hasattr(rect,'get_height') and not np.isnan(rect.get_height())]) | |
for rect in rects: | |
if hasattr(rect,'get_height'): | |
height = rect.get_height() | |
if not np.isnan(height): | |
ax.text(rect.get_x()+rect.get_width()/2., height-.1*max_height, '%d'%int(height), | |
ha='center', va='bottom',color='w') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Use case for plotting a barchart using a Pandas DataFrame called
df
: