Regression Plots (lmplot, regplot)
Why regression plots?
Regression plots help you see:
- Trend direction
- Strength of relationship (visual)
- Outliers that affect the trend
flowchart LR A["x, y columns"] --> B["Scatter every point"] A --> C["Fit a regression line
(linear by default)"] C --> D["Shade a confidence
band around the line"] B --> E["regplot figure"] D --> E
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:
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 coffeeWas this page helpful?
Let us know how we did
