Seaborn can fit and draw a regression line straight onto a scatter. regplot (axes-level) and lmplot (figure-level, faceted) add a fitted trend with a confidence band — a fast way to see and communicate a relationship.
regplot & lmplot
sns.regplot(data=tips, x="total_bill", y="tip") # scatter + linear fit + CIsns.lmplot(data=tips, x="total_bill", y="tip",hue="smoker", col="time") # a fit per group, faceted
Non-linear & robust fits
sns.regplot(data=df, x="x", y="y", order=2) # polynomial (quadratic) fitsns.regplot(data=df, x="x", y="y", lowess=True) # smooth local regressionsns.regplot(data=df, x="x", y="y", robust=True) # down-weight outliers
Key takeaways
- 01regplot (axes-level) and lmplot (figure-level, faceted) add a fitted regression line + CI.
- 02lmplot facets a separate fit per hue/col/row group.
- 03order= fits a polynomial; lowess=True fits a smooth local curve; robust= resists outliers.
- 04The band is the fit's confidence interval — don't extrapolate beyond the data.
