Xfce4
Xfce4

Reputation: 567

seaborn.boxenplot - How to display the mean values?

showmeans = True in boxplot diplays the means.

Is there a way to display mean values for seaborn.boxenplot in addition to the median line?

What would be a low cost but detailed (similar to boxenplot) solution?

P.S. Google search motors can not distinguish the difference between boxenplot and boxplot.


EDIT: THE RESULT FOLLOWING YOZHIKOFF'S SOLUTION: enter image description here code:

fig = plt.figure(figsize = (12,5))
a1 = sns.boxenplot(y = 'price', x = 'grade', data=df2 )
a1 = sns.scatterplot(data=df2.groupby('grade')['price'].mean(), zorder=10)
a1.set(yscale='log')
plt.xticks(rotation=60);

Upvotes: 1

Views: 1729

Answers (1)

Yozhikoff
Yozhikoff

Reputation: 66

One way to approach it would be to simply draw means separately, so altering the seaborn.boxenplot example from the docs a bit we have this

import seaborn as sns

sns.set_theme(style="whitegrid")

tips = sns.load_dataset("tips")
proxy_df = tips.groupby('day')["total_bill"].mean().to_frame().reset_index()

ax = sns.stripplot(x="day",  y="total_bill", data=proxy_df, zorder=10,  color='C0', linewidth=1, jitter=False, edgecolor='lightgray')
ax = sns.boxenplot(x="day", y="total_bill", data=tips)

Note that we use zorder here to force means to be drawn on top of boxenplots.

Upvotes: 3

Related Questions