Below is my datasheet and sample graph
As you can above x-axis is consist of day and y-axis is consist of tip and hue is set to sex. I want the count of bar i.e for (Male)light pink number should be 8 because there are 8 male who gave tip on sunday and likewise Female should be 1. I know how to display number on the top of the graph. I don't know how to get the count i.e 8 and 1
import seaborn as sns
import matplotlib.pyplot as plt
sns.set_theme(style="whitegrid")
df = sns.load_dataset("tips")[1:10]
print(df)
ax = sns.barplot(x='day', y='tip',hue="sex", data=df, palette="tab20_r")
for rect in ax.patches:
y_value = rect.get_height()
x_value = rect.get_x() + rect.get_width() / 2
space = 1
label = "{:.0f}".format(y_value)
ax.annotate(label, (x_value, y_value), xytext=(0, space), textcoords="offset points", ha='center', va='bottom')
plt.show()
Above is the code for the sample image. If you understood my question. Any help would be great. If you didn't undertood my question you can ask me in comment. what you didn't understood
There are 3 questions on SO which are completely different for somewhat reason SO is marking this question as duplicate and link for the same
How to display custom values on a bar plot
How to plot and annotate grouped bars in seaborn / matplotlib
How to annotate a barplot with values from another column