How to display the value on horizontal bars

Update: there’s a built in method for this now! Scroll down a couple answers to “New in matplotlib 3.4.0”.

If you can’t upgrade that far, it doesn’t take much code. Add:

for i, v in enumerate(y):
    ax.text(v + 3, i + .25, str(v), color="blue", fontweight="bold")

result:

enter image description here

The y-values v are both the x-location and the string values for ax.text, and conveniently the barplot has a metric of 1 for each bar, so the enumeration i is the y-location.

Leave a Comment