show avg value in sns boxplot

Solutions on MaxInterview for show avg value in sns boxplot by the best coders in the world

showing results for - "show avg value in sns boxplot"
Guillermo
06 May 2016
1import seaborn as sns
2
3sns.set_style("whitegrid")
4tips = sns.load_dataset("tips")
5box_plot = sns.boxplot(x="day",y="total_bill",data=tips)
6
7medians = tips.groupby(['day'])['total_bill'].median()
8vertical_offset = tips['total_bill'].median() * 0.05 # offset from median for display
9
10for xtick in box_plot.get_xticks():
11    box_plot.text(xtick,medians[xtick] + vertical_offset,medians[xtick], 
12            horizontalalignment='center',size='x-small',color='w',weight='semibold')