I need to scatter plot data with its own line by type with a comparison to a reference line for each facet. I am wrestling with getting the line equation y=8x+10 to plot on each facet plot.
import pandas as pd
import seaborn as sns
sns.lmplot(x="18O‰ VSMOW", y="D‰ VSMOW", hue="Type",
col="Type", col_wrap=2, data=df)
My goal is to enable easy comparison of each Type to a known general relationship. Below, I drew in what I would like on the top two plots:
axline()
to easily plot reference lines.lmplot
return a FacetGrid, so store the grid to access the facets.Either use FacetGrid.map_dataframe()
to apply axline
to each facet:
# store underlying facet grid
g = sns.lmplot(x='total_bill', y='tip', col='day', hue='day', col_wrap=2, data=df)
# apply axline to each facet (y = 0.18*x - 0.3)
g.map_dataframe(lambda data, **kws: plt.axline((0, -0.3), slope=0.18))
Or iterate the facets manually via g.axes.flat
:
for ax in g.axes.flat:
ax.axline((0, -0.3), slope=0.18) # y = 0.18*x - 0.3
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With