Categories
Python Answers

How to annotate bars with values on Python Pandas bar plots?

Spread the love

To annotate bars with values on Python Pandas bar plots, we call the annotate metthod.

For instance, we write

for p in ax.patches:
    ax.annotate(str(p.get_height()), (p.get_x() * 1.005, p.get_height() * 1.005))

to loop through the axes ax patches with ax.patches with a for loop.

Then we call ax.annotate to add the anootation for each patch by calling it with the position of the annotation.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *