本文介绍了Seaborn中标值的箱形图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何在海洋图中用中位数标记每个箱形图?
How can I label each boxplot in a seaborn plot with the median value?
例如
import seaborn as sns
sns.set_style("whitegrid")
tips = sns.load_dataset("tips")
ax = sns.boxplot(x="day", y="total_bill", data=tips)
如何用中位数或平均值标记每个箱形图?
How do I label each boxplot with the median or average value?
推荐答案
当人们包括样本数据集时,我很喜欢!
I love when people include sample datasets!
import seaborn as sns
sns.set_style("whitegrid")
tips = sns.load_dataset("tips")
box_plot = sns.boxplot(x="day",y="total_bill",data=tips)
medians = tips.groupby(['day'])['total_bill'].median()
vertical_offset = tips['total_bill'].median() * 0.05 # offset from median for display
for xtick in box_plot.get_xticks():
box_plot.text(xtick,medians[xtick] + vertical_offset,medians[xtick],
horizontalalignment='center',size='x-small',color='w',weight='semibold')
这篇关于Seaborn中标值的箱形图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!