1

I am trying to subplot multiple curves and show the percentile for each subset. however, with my current code it only plots the percentile of the whole dataset, not for each sample.

enter image description here

Code:

sns.set_theme()
grid = sns.FacetGrid(hist, col='Region',   height=4.3, sharey=False, sharex=False, margin_titles=False, row= 'Surname')
grid = grid.map(sns.histplot, 'Age',kde=True)



def vertical_mean_line_survived(x, **kwargs):

    Q1=np.percentile(hist['Age'], 10)
    Q2=np.percentile(hist['Age'], 90)

    plt.axvline(Q1, color='r', linestyle='--')
    plt.axvline(Q2, color='r', linestyle='--')
    
    
grid.map(vertical_mean_line_survived, 'Age') 

grid.fig.subplots_adjust(top=0.8)

plt.subplots_adjust(hspace=0.4)

Thank you!!

CrisXP
  • 31
  • 4
  • 1
    You are using the `hist` variable in your percentile annotation function, when you should be using `x`. Take a look at the answers in [How to add a mean and median line to a Seaborn displot](https://stackoverflow.com/q/67613774/3279716). [`displot`](https://seaborn.pydata.org/generated/seaborn.displot.html) is a wrapper for FacetGrid with distribution plots – Alex Jan 21 '22 at 11:05

0 Answers0