Skip to content

Regression Plots (lmplot, regplot)

Why regression plots?

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.

regplotregplot (axes-level)

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()
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()

lmplotlmplot (figure-level, great for facets)

lmplot
import seaborn as sns
 
tips = sns.load_dataset("tips")
 
sns.lmplot(data=tips, x="total_bill", y="tip", hue="sex")
lmplot
import seaborn as sns
 
tips = sns.load_dataset("tips")
 
sns.lmplot(data=tips, x="total_bill", y="tip", hue="sex")

Visualize it

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.

Non-linear patterns

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()
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()

Tips

  • Regression plots show association, not causation.
  • Outliers can heavily affect the fitted line.
  • Use transformations (log) if relationships are multiplicative.

Next

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

🧪 Try It Yourself

Exercise 1 – Fit a Regression Line

Exercise 2 – Facet the Regression by Group

Exercise 3 – Try a Quadratic Fit

If this helped you, consider buying me a coffee ☕

Buy me a coffee

Was this page helpful?

Let us know how we did