I want to add vertical lines in a sns.facetgrid() - How can I do that?


Screen Link:

My Code:


g = sns.FacetGrid(titanic, col="Pclass", size=6)
g.map(sns.kdeplot, "Age", shade=True)
sns.despine(left=True, bottom=True)

plt.axvline(x=40, color='r', linestyle='-')

plt.show()

What I expected to happen:

I would want the vertical line at the same place in every single graph as a reference.

1 Like

Why return g? https://realpython.com/python-matplotlib-guide/

Try this

g.map(plt.axvline, x=40, color=β€œred”, dashes=(2, 1), zorder=0,linewidth=2)