Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
-
Economics & Finance
Difference between regplot(), lmplot() and residplot()?
Seaborn is a Python data visualization library built on matplotlib that provides high-level statistical plotting functions. Three important functions for regression analysis are regplot(), lmplot(), and residplot(), each serving different purposes in visualizing linear relationships.
Key Differences
| Feature | regplot() | lmplot() | residplot() |
|---|---|---|---|
| Purpose | Simple regression plot | Regression with faceting | Residual analysis |
| Plot Type | Scatter + regression line | Multiple regression plots | Residuals scatter plot |
| Grouping | Single plot | Supports hue, col, row | Single plot |
| Returns | Axes object | FacetGrid object | Axes object |
seaborn.regplot()
Creates a scatter plot with a fitted regression line and confidence interval ?
Syntax
seaborn.regplot(x, y, data=None, x_estimator=None, x_bins=None,
x_ci='ci', scatter=True, fit_reg=True, ci=95,
n_boot=1000, units=None, order=1, logistic=False,
lowess=False, robust=False, logx=False,
x_partial=None, y_partial=None, truncate=False,
dropna=True, x_jitter=None, y_jitter=None,
label=None, color=None, marker='o',
scatter_kws=None, line_kws=None, ax=None)
Example
import seaborn as sns
import matplotlib.pyplot as plt
# Load sample data
tips = sns.load_dataset("tips")
# Create regplot
plt.figure(figsize=(8, 6))
sns.regplot(x="total_bill", y="tip", data=tips)
plt.title("Regplot: Total Bill vs Tip")
plt.show()
seaborn.lmplot()
Combines regplot() with FacetGrid to create multiple regression plots with grouping variables ?
Example
import seaborn as sns
import matplotlib.pyplot as plt
# Load sample data
tips = sns.load_dataset("tips")
# Create lmplot with grouping
sns.lmplot(x="total_bill", y="tip", hue="smoker", data=tips, height=6)
plt.title("Lmplot: Total Bill vs Tip by Smoker Status")
plt.show()
Key Parameters
- x, y ? Variable names for x and y axes
- hue ? Variable for color grouping
- col, row ? Variables for creating subplot grids
- data ? DataFrame containing the data
- fit_reg ? Whether to fit regression line (default True)
seaborn.residplot()
Plots residuals of a linear regression to check model assumptions ?
Syntax
seaborn.residplot(x, y, data=None, lowess=False, x_partial=None,
y_partial=None, order=1, robust=False, dropna=True,
label=None, color=None, scatter_kws=None,
line_kws=None, ax=None)
Example
import seaborn as sns
import matplotlib.pyplot as plt
# Load sample data
tips = sns.load_dataset("tips")
# Create residplot
plt.figure(figsize=(8, 6))
sns.residplot(x="total_bill", y="tip", data=tips, lowess=True)
plt.title("Residplot: Checking Linear Regression Assumptions")
plt.show()
When to Use Each Function
- regplot() ? Use for simple two-variable regression visualization
- lmplot() ? Use when you need to compare relationships across different groups or categories
- residplot() ? Use to validate regression model assumptions by examining residual patterns
Conclusion
regplot() is ideal for simple regression visualization, lmplot() excels at grouped regression analysis with faceting capabilities, and residplot() is essential for model diagnostics. Choose based on whether you need basic plotting, grouping, or residual analysis.
