4

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:

Current Plot

tdy
  • 36,675
  • 19
  • 86
  • 83

1 Answers1

3

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

tdy
  • 36,675
  • 19
  • 86
  • 83