Skip to content

Regression Plots (lmplot, regplot)

Regression plots help you see:

  • Trend direction
  • Strength of relationship (visual)
  • Outliers that affect the trend
diagram What regplot draws mermaid
regplot combines a scatter plot with a fitted line and a shaded confidence band around it.
regplot
import seaborn as sns
import matplotlib.pyplot as plt
 
tips = sns.load_dataset("tips")
 
plt.figure(figsize=(7, 4))
sns.regplot(data=tips, x="total_bill", y="tip")
plt.title("Tip vs total bill")
plt.tight_layout()
plt.show()
lmplot
import seaborn as sns
 
tips = sns.load_dataset("tips")
 
sns.lmplot(data=tips, x="total_bill", y="tip", hue="sex")

The line summarizes the overall trend; the shaded band shows how confident the fit is — narrower where data is dense, wider near the edges:

sketch Scatter plot with a fitted trend line p5.js
Dots are individual data points; the blue line is the fitted trend, with a soft confidence band around it.

You can try polynomial fits.

Polynomial fit
import seaborn as sns
import matplotlib.pyplot as plt
 
tips = sns.load_dataset("tips")
 
plt.figure(figsize=(7, 4))
sns.regplot(data=tips, x="total_bill", y="tip", order=2)
plt.title("Quadratic trend")
plt.tight_layout()
plt.show()
  • Regression plots show association, not causation.
  • Outliers can heavily affect the fitted line.
  • Use transformations (log) if relationships are multiplicative.

Continue to Joint Plots to see the same scatter relationship alongside each variable’s own distribution.

Exercise 2 – Facet the Regression by Group

Section titled “Exercise 2 – Facet the Regression by Group”

pch.coffeeTagline

pch.coffeeCta

pch.feedbackHeading

pch.feedbackSubheading