本文介绍了为 seaborn FacetGrid distplots 添加均值和可变性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
向 seaborn FacetGrid 中的每个直方图添加代表均值(或其他集中趋势度量)的点和可变性度量(例如,标准偏差或置信区间)的最佳方法是什么?
结果应该类似于
(不知道为什么 0.01
稍微向右移动...)
What is the best way to add a point representing the mean (or another measure of central tendency) and a measure of variability (e.g., standard deviation or confidence interval) to each histogram in a seaborn FacetGrid?
The result should look similar to the figure shown here, but with a mean/SD in each of the FacetGrid subplots. This is a related question for the non-FacetGrid case.
解决方案
Based on @mwaskom's comment, here is one possible solution (using boxplot, analogous for pointplot):
tips = sns.load_dataset("tips")
sns.set(font_scale=1.3)
def dist_boxplot(x, **kwargs):
ax = sns.distplot(x, hist_kws=dict(alpha=0.2))
ax2 = ax.twinx()
sns.boxplot(x=x, ax=ax2)
ax2.set(ylim=(-5, 5))
g = sns.FacetGrid(tips, col="sex")
g.map(dist_boxplot, "total_bill");
(Not sure why the 0.01
is shifted slightly rightwards...)
这篇关于为 seaborn FacetGrid distplots 添加均值和可变性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!