2016-10-16 32 views
1

什麼是向每個直方圖添加代表平均值(或另一箇中心傾向度量)的點以及對每個直方圖的可變性度量(例如,標準偏差或置信區間)的最佳方式是什麼? Seaborn FacetGrid?向seaborn FacetGrid空間添加平均值和可變性

結果應該看起來類似於here所示的圖形,但在每個FacetGrid子圖中均值/ SD。 This是非FacetGrid案例的相關問題。

+0

可能有幫助:https://seaborn.github.io/tutorial/axis_grids.html#mapping-custom-functions-onto-the-grid – mwaskom

回答

0

基於@ mwaskom的評論,這裏是一個可能的解決方案(使用箱線圖,爲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"); 

"distplot plus boxplot"

(不知道爲什麼0.01略微向右轉移......)