Seaborn: Adding annotations option (attributes) to barplot and countplot

Created on 7 Oct 2018  路  5Comments  路  Source: mwaskom/seaborn

I propose for adding annotations option (attributes) to barplot and countplot
Lets start with an example
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
%matplotlib inline

df = sns.load_dataset('tips')

Plotting a simple barplot

splot = sns.barplot(data=df, x = 'sex', y = 'total_bill')
default

Annotating bars
plt.figure(figsize=(6, 8))
splot = sns.barplot(data=df, x = 'sex', y = 'total_bill', ci = None)
for p in splot.patches:
splot.annotate(format(p.get_height(), '.2f'), (p.get_x() + p.get_width() / 2., p.get_height()), ha = 'center', va = 'center', xytext = (0, 10), textcoords = 'offset points')

annotated

This seems a simple addition. But, someone requiring to add some more highlights by annotating those bar would require to add some more lines of code.

Instead, adding a single attribute would reduce this efforts and make them more expressive !!!!!

Most helpful comment

I would really like to see this or something like this added.

The annotation on barplots should be simple.

All 5 comments

I won鈥檛 be adding this, sorry.

I would really like to see this or something like this added.

The annotation on barplots should be simple.

Thanks for the Post. Can you tell me how to annotate if I have a horizontal plot?

Thanks for the post, very helpful!

Sorry, could you help on doing the same, but with the sex at the Y-axis?

Was this page helpful?
0 / 5 - 0 ratings

Related issues

sofiatti picture sofiatti  路  4Comments

Bercio picture Bercio  路  3Comments

stonebig picture stonebig  路  4Comments

chanshing picture chanshing  路  3Comments

songololo picture songololo  路  4Comments