how to add percentage in countplot

Solutions on MaxInterview for how to add percentage in countplot by the best coders in the world

showing results for - "how to add percentage in countplot"
Giulia
18 Aug 2017
1sns.set(style="whitegrid")
2plt.figure(figsize=(8,5))
3total = float(len(train_df))
4ax = sns.countplot(x="event", hue="event", data=train_df)
5plt.title('Data provided for each event', fontsize=20)
6for p in ax.patches:
7    percentage = '{:.1f}%'.format(100 * p.get_height()/total)
8    x = p.get_x() + p.get_width()
9    y = p.get_height()
10    ax.annotate(percentage, (x, y),ha='center')
11plt.show()
12
similar questions
queries leading to this page
how to add percentage in countplot