'seaborn histplot - print y-values above each bar [duplicate]

How to print y-values above each bar, please? Thank you

import matplotlib.pyplot as plt
import seaborn as sns

data = [6, 3, 1, 5, 2, 7, 3, 1, 9, 2, 1, 4, 2, 6, 3, 9, 4, 1, 7, 3, 1, 9, 2, 1, 4, 2, 1, 3, 1, 4, 2, 7, 3, 1, 5, 2, 7, 3, 1, 5, 1, 8, 4, 1, 6, 3, 1, 5, 2, 7, 3, 1, 5, 2, 8, 4, 1, 6, 3, 9, 4, 1, 7, 2, 1, 3, 1, 4, 7, 3, 1, 9, 2, 1, 4, 2, 1, 3, 1, 4, 2, 7, 3, 1, 5, 2, 7, 3, 1, 5, 1, 8, 4, 1, 6, 3, 1, 5, 2, 7, 3, 1, 5, 2, 8, 4, 1, 6, 3, 9, 4, 1, 7, 2, 1, 3, 1, 4, 2, 7, 3, 1, 9, 2, 1, 4, 2, 6, 3, 9, 4, 2, 1, 5, 1, 8, 4, 1, 6, 3, 9, 4, 2, 1, 6, 1, 9, 4, 2, 7, 3, 1, 5, 1, 8, 4, 2, 1, 5, 1, 8, 4, 2, 1, 9, 4, 1, 7, 3, 1, 5, 1, 8, 2, 1, 6, 3, 9, 4, 2, 1, 5, 2, 1, 4, 2, 6, 3, 1, 5, 2, 1, 6, 3, 9, 4, 2, 7, 3, 1, 5, 2, 7, 3, 1, 5, 2, 8, 4, 1, 6, 3, 1, 5, 2, 7, 3, 1, 9, 2, 1, 4, 2, 6, 3, 9, 4, 1, 7, 3, 1, 9, 2, 1, 4, 2, 1, 3, 1, 4, 2, 7, 3, 1, 5, 2, 7, 3, 1, 5, 1, 8, 4, 1, 6, 3, 1, 5, 2]

fig, ax = plt.subplots()

ax = sns.histplot(data, discrete=True, kde=False, stat='percent') 

plt.show()


Solution 1:[1]

If you have matplotlib 3.4.0 or higher, you can use bar_label. More info here

Code would be something like this...

ax = sns.histplot(data, discrete=True, kde=False, stat='percent') 
ax.bar_label(ax.containers[0])

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Redox