Skip to main content
Albero Academy

Regression Plots

Fit and visualise a trend line with regplot and lmplot.

Regression & Matrix8 min

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

scatter + fitted line
sns.regplot(data=tips, x="total_bill", y="tip") # scatter + linear fit + CI
sns.lmplot(data=tips, x="total_bill", y="tip",
hue="smoker", col="time") # a fit per group, faceted

Non-linear & robust fits

beyond a straight line
sns.regplot(data=df, x="x", y="y", order=2) # polynomial (quadratic) fit
sns.regplot(data=df, x="x", y="y", lowess=True) # smooth local regression
sns.regplot(data=df, x="x", y="y", robust=True) # down-weight outliers

Key takeaways

  1. 01regplot (axes-level) and lmplot (figure-level, faceted) add a fitted regression line + CI.
  2. 02lmplot facets a separate fit per hue/col/row group.
  3. 03order= fits a polynomial; lowess=True fits a smooth local curve; robust= resists outliers.
  4. 04The band is the fit's confidence interval — don't extrapolate beyond the data.

Finished this chapter?

Mark it complete to track your progress through Seaborn.