A better way to add labels to bar charts with matplotlib

Lately, I’ve been using Python’s matplotlib plotting library to generate a lot of figures, such as, for instance, the bar charts I showed in this talk.

To improve readability, I like to put a number label at the top of each bar that gives the quantity that that bar represents. When I realized I wanted to add these labels to my charts, the first thing I did was look at this example from the matplotlib documentation, which seemed to be doing something a lot like what I wanted:

I finally finished my dissertation!

Last September, after defending my dissertation, I breezily predicted that I would finish writing and turn it in “sometime in the next couple of months”. A year later, I’m happy and relieved to announce that I’ve finally finished the thing! My official graduation date is September 30.1