Course contentsShow
← Data Science
Lesson 1289 of 2,14532. Visualization with Matplotlib and SeabornFree lesson

Regression Plots: regplot and lmplot

Adding regression lines and confidence bands to scatterplots for relationship exploration.

Regression Plots: regplot and lmplot

You'll learn how to add regression lines and confidence bands to scatterplots to quickly visualize relationships between variables.

What Are Regression Plots?

When exploring relationships between two continuous variables, a scatter plot shows you the raw data points—but sometimes you need more. Regression plots overlay a fitted line and confidence interval on top of your scatter plot, giving you an instant visual summary of the relationship's direction, strength, and uncertainty.

Think of it like drawing a "line of best fit" through a cloud of points, then shading the area around it to show "I'm this confident the true relationship lies in this band."

Two Tools: regplot and lmplot

Seaborn offers two functions for regression visualization:

regplot() creates a single regression plot on the current axes. It's straightforward and integrates easily with Matplotlib's subplot system:

import seaborn as sns
import matplotlib.pyplot as plt

sns.regplot(data=df, x='age', y='income')
plt.show()

lmplot() is a figure-level function that creates its own figure and can handle faceting (creating separate plots for different subgroups using col= or row=):

sns.lmplot(data=df, x='age', y='income', hue='gender', col='education')

Both add a regression line by default and show the 95% confidence interval as a shaded band. You can disable the line with fit_reg=False or adjust confidence levels.

When to Use Them

Use regression plots during exploratory analysis to quickly assess whether two variables have a linear relationship, how strong it appears, and whether different groups show different patterns.

Key Takeaway: regplot() and lmplot() add regression lines and confidence bands to scatter plots, making relationships and their uncertainty immediately visible—use regplot() for simple cases and lmplot() when you need faceting by categories.