How to insert an constant horizontal line on a seaborn catplot

Viewed 1047

I would like to add a constant horizontal line on a seaborn catplot for all the subplots that was created - here is my codes :

sns.set()
fig = sns.catplot(x="LARGF", y="F_tot", hue="pass_inv", col="EPF", data=df_pi1_2_ag, kind="boxen", height=10, aspect=.7)

enter image description here

2 Answers

@zabop : here my MCEV:

data = [[7,1800,2354,1],[7,1800,2352,2], [7,1800,2356,1],[7,1800,2357,2],\
        [8,1800,2554,1],[8,1800,2552,2], [8,1800,2556,1],[8,1800,2557,2]]
df = pd.DataFrame(data, columns = ['EPF', 'LARGF','F_tot','pass_inv']) 
fig = sns.catplot(x="LARGF", y="F_tot", hue="pass_inv", col="EPF", data=df, kind="boxen", height=5, aspect=.7)

output

And I want to add a constant horizontal line at y=2500 on both graphics fromt the catplot (FacetGrid)

You can use the function refline. See the docs for refline. This can be found when looking at the documentation for a FacetGrid object which is returned by sns.catplot. There you can find further examples.

Here is the result for your minimal working example: enter image description here

sns.set_theme()
data = [[7,1800,2354,1],[7,1800,2352,2], [7,1800,2356,1],[7,1800,2357,2],\
        [8,1800,2554,1],[8,1800,2552,2], [8,1800,2556,1],[8,1800,2557,2]]
df = pd.DataFrame(data, columns = ['EPF', 'LARGF','F_tot','pass_inv']) 
fig = sns.catplot(x="LARGF", y="F_tot", hue="pass_inv", col="EPF", data=df, kind="boxen", height=5, aspect=.7)
fig.refline(y=2500, color='red')
Related