I have a seaborn count plot, but instead of colour bars I need the value above each bar. My input is pandas data frame.
ax = sns.countplot(x="variable", hue="value", data=pd.melt(dfs))
here dfs has many entries for different columns.
For example, here "man" above the blue bar, "woman" above the brown bar and "child" above the green bar instead of the colour description.
Sometimes it's easier to not try to find ways to tweak seaborn, but rather to directly use matplotlib and build a chart up from scratch.
Here, we can assume to have a dataframe named
counts
that looks likewhere the index are the positions along x axis and the columns are the different hues. In the following,
groupedbarplot
is a function to take such dataframe as input and plot the bars as groups, and in addition add a label to each one of them.We could also label the values directly,
groupedbarplot(counts, annotate="values")