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
regplot (axes-level)
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 (figure-level, great for facets)
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.
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.
Check your understanding
What does sns.regplot draw?
regplot makes a scatter plot and fits a linear regression line with a confidence band.
Show answer
A — A scatter plot with a fitted linear regression line — regplot makes a scatter plot and fits a linear regression line with a confidence band.
What is the key difference between regplot and lmplot?
regplot is axes-level while lmplot is figure-level and great for facets.
Show answer
B — lmplot is figure-level and supports hue and facets — regplot is axes-level while lmplot is figure-level and great for facets.
What does order=2 do in sns.regplot(..., order=2)?
order sets the polynomial degree, so order=2 is a quadratic trend for non-linear patterns.
Show answer
B — Fits a quadratic (polynomial) trend — order sets the polynomial degree, so order=2 is a quadratic trend for non-linear patterns.
The tip versus total_bill line slopes upward. What can you conclude from the plot alone?
The lesson stresses that regression plots show association, not causation, and outliers can heavily affect the line.
Show answer
B — An association, but not causation — The lesson stresses that regression plots show association, not causation, and outliers can heavily affect the line.
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
Tab indents. Press Escape, then Tab, to leave the editor. Control plus Enter runs the code; Control plus Shift plus Enter submits it.
Press Run to see what your code prints.Exercise 2 – Facet the Regression by Group
Tab indents. Press Escape, then Tab, to leave the editor. Control plus Enter runs the code; Control plus Shift plus Enter submits it.
Press Run to see what your code prints.Exercise 3 – Try a Quadratic Fit
Tab indents. Press Escape, then Tab, to leave the editor. Control plus Enter runs the code; Control plus Shift plus Enter submits it.
Press Run to see what your code prints.