Written and maintained by CASRAI Editorial Board
Published
On this page
sns.regplot (seaborn.regplot) draws a scatter plot of two variables and fits a regression line to them in one call, with a bootstrapped confidence band around the line. It is an axes-level function: it draws onto a single matplotlib Axes and returns that Axes, so it gives you a picture of the fit but not the fitted coefficients. The shortest working call is sns.regplot(data=df, x="col_a", y="col_b"), and everything else on this page is about the arguments that change the fit, the band and the points.
What sns.regplot is used for in research
Researchers use regplot as an exploratory check on how one measured variable relates to another before a model is reported. It combines the scatter of the raw observations with a least-squares line by default, so a reader can see the trend and the spread around it in the same panel. The seaborn regression tutorial frames the purpose as a way to emphasise patterns in a dataset during exploratory analysis, and it uses Anscombe’s quartet to show why the picture matters: datasets I and II share the same linear fit, but dataset II is clearly nonlinear when plotted.
Because regplot returns only an Axes, it is a visual tool, not a reporting tool. If a manuscript needs a slope, intercept or p-value, compute them with a statistics routine (see the linear regression scatter plot guide for the stats side) and use regplot to illustrate them.
seaborn regplot versus lmplot and the other regression plots
seaborn.regplot and seaborn.lmplot are closely related. The seaborn documentation describes regplot as axes-level and lmplot as a figure-level function that combines regplot and FacetGrid. In practice that decides which one you can call, as the table below summarises from the official regression tutorial and the regplot notes.
| Function | Level | What the documentation says |
|---|---|---|
| regplot | Axes-level | Accepts x and y as numpy arrays, pandas Series or DataFrame columns; draws onto an existing Axes through ax. |
| lmplot | Figure-level (regplot plus FacetGrid) | Requires data and string names for x and y; only lmplot has hue, so per-group lines belong here. |
| jointplot and pairplot with kind=”reg” | Figure-level, built on JointGrid and PairGrid | Draw regression fits but do not directly accept all of regplot’s parameters. |
| residplot | Axes-level | Plots the residuals of a linear fit; the tutorial says residuals should scatter randomly around y = 0. |
For faceted layouts see the seaborn FacetGrid guide, and for all pairwise relationships at once see the seaborn pairplot guide.
Install or access
seaborn is installed from its official channels. The seaborn installation page lists pip install seaborn and conda install seaborn -c conda-forge, and an extended form, pip install seaborn[stats], for the optional statistical dependencies. It requires Python 3.8 or later and depends on numpy, pandas and matplotlib; statsmodels is an optional dependency for advanced regression plots, and scipy is also optional. The installation page showed version 0.13.2 as the latest release when it was read on 2026-11-15.
The statsmodels dependency matters for this function specifically: the regplot parameters logistic, lowess and robust use statsmodels, so an environment without it can draw the default linear fit but not those variants.
Step-by-step: draw and refine a regression plot
1. Import and load data
regplot reads columns from a DataFrame passed as data. This worked example uses the Anscombe dataset that seaborn’s tutorial uses, loaded with load_dataset:
import seaborn as snsimport matplotlib.pyplot as pltanscombe = sns.load_dataset("anscombe")ds2 = anscombe.query("dataset == 'II'")
2. Draw the default linear fit
sns.regplot(data=ds2, x="x", y="y")plt.show()
This draws the scatter, a straight least-squares line and a 95% confidence band (the signature default is ci=95). Anscombe’s dataset II lies on a curve, so the straight line will visibly misfit it even though its linear fit matches dataset I.
3. Check the residuals
sns.residplot(data=ds2, x="x", y="y")plt.show()
The seaborn tutorial recommends residplot to check whether a simple linear model is appropriate: residuals should scatter randomly around zero, and visible structure means a linear regression is the wrong model. Dataset II shows a clear pattern.
4. Refit with a polynomial and drop the band
sns.regplot(data=ds2, x="x", y="y", order=2, ci=None)plt.show()
With order greater than 1, regplot uses numpy.polyfit to estimate a polynomial regression. The tutorial applies order=2 with ci=None to dataset II. Setting ci=None skips the bootstrap entirely, which the documentation says may be advisable for large datasets.
5. Style the points and line separately
sns.regplot(data=ds2, x="x", y="y", order=2, ci=None, scatter_kws={"s": 80}, line_kws={"color": "r"})
scatter_kws and line_kws pass keyword arguments to plt.scatter and plt.plot. The color argument is overridden by values set in these dictionaries.
6. Draw onto a specific Axes
fig, axes = plt.subplots(1, 2, figsize=(9, 4))sns.regplot(data=anscombe.query("dataset == 'I'"), x="x", y="y", ax=axes[0])sns.regplot(data=ds2, x="x", y="y", order=2, ci=None, ax=axes[1])
Because regplot is axes-level, ax places each plot in your own matplotlib layout. This is how you build a multi-panel figure without lmplot.
Arguments that change the result
The data table below lists the regplot arguments that alter the fit, the interval or the points, with the defaults from the function signature and the behaviour stated in the documentation. A recurring theme is that some arguments change the fitted model and others only change how the points are drawn.
Choosing the model: order, logistic, lowess, robust, logx
Each of these replaces the straight-line fit. order fits a polynomial through numpy.polyfit. logistic=True assumes y is binary and fits a logistic regression through statsmodels; the tutorial draws the line as the estimated probability that y equals 1 and suggests y_jitter=.03 to keep the binary points visible. lowess=True fits locally weighted linear regression and the tutorial notes it makes the fewest assumptions, but confidence intervals cannot currently be drawn for it. robust=True de-weights outliers. logx=True fits y ~ log(x) but plots in the original input space, which requires x to be positive.
Controlling the confidence band: ci, n_boot, seed, units
ci sets the size of the band and the interval is estimated by bootstrap. n_boot is the number of resamples; the documentation says the default balances time and stability and suggests raising it for final versions of plots. seed makes the bootstrap reproducible. units is used for multilevel bootstrapping and affects the confidence intervals only. For the logistic and robust fits the documentation warns they are substantially more computationally intensive, and advises reducing n_boot or setting ci=None.
Discrete predictors: x_jitter, x_estimator, x_bins
x_jitter and y_jitter add uniform noise to a copy of the data after fitting, so they change only how the scatter looks. x_estimator applies a function such as np.mean to each unique x value, and a confidence interval is bootstrapped when x_ci is set. x_bins bins x for display only; the regression is still fit to the original data, and using it implies an x_estimator default of numpy.mean.
Line extent: truncate
With truncate=True (the default) the line is bounded by the data limits; with False it extends to the x-axis limits.
Output and how to read it
regplot returns the matplotlib Axes it drew on. The visible output has three parts: the scatter of observations, the fitted line, and the translucent band that shows the bootstrap confidence interval for the fitted line. The band describes uncertainty in the estimated regression line, not the spread of individual observations, so many points lying outside the band is normal.
Read the plot in this order. First, check whether the observations actually follow the line shape you fitted; Anscombe’s datasets I and II share a linear fit, and only the plot (or a residual plot) shows that II is nonlinear. Second, look at the residuals when the choice of model is in doubt. Third, if a number is needed, compute it outside the plot: the Axes object holds the drawn artists, not a regression results table, so report fitted coefficients from a statistics routine and cite the plot only as the illustration.
Troubleshooting
hue is not accepted
regplot has no hue argument; the seaborn tutorial states only lmplot has it. Use lmplot for one fit line per group, or call regplot once per subset onto the same ax.
The plot is slow or hangs on large data
The confidence band is bootstrapped. Set ci=None, or reduce n_boot, particularly with logistic, robust or other statsmodels-backed options.
An import error with logistic, lowess or robust
These options use statsmodels, which the installation page lists as an optional dependency. Install it (for example through pip install seaborn[stats]) before using them.
logx fails or gives nonsense
The documentation requires x to be positive when logx=True. Remove or recode zero and negative values first.
lowess shows no confidence band
This is documented behaviour: confidence intervals cannot currently be drawn for the lowess model.
Jitter appears to change the fit
It does not. Jitter is added to a copy of the data after fitting and only changes the scatter drawing.
Passing arrays instead of columns
regplot accepts numpy arrays, pandas Series or DataFrame columns for x and y, whereas lmplot requires data and string names. Switching a call from lmplot to regplot therefore usually means passing the columns directly or keeping the string names with data=.
Free alternatives
All of the tools in the table are open-source Python libraries, and each overlaps with part of what regplot does. The statements come from the seaborn documentation pages listed under Sources.
| Tool | Relationship to regplot |
|---|---|
| seaborn.lmplot | Figure-level version combining regplot and FacetGrid; supports hue and facets. |
| seaborn.residplot | Companion function for checking whether a linear fit is appropriate. |
| statsmodels | The library regplot itself calls for logistic, lowess and robust fits; use it directly when you need the model results. |
| numpy.polyfit | The routine regplot uses when order is greater than 1. |
| matplotlib (plt.scatter, plt.plot) | Receives scatter_kws and line_kws; usable directly for fully manual figures. |
For other Python plotting tasks see the scatter plot in Python guide.
Frequently asked questions
What does sns.regplot do?
It plots data and a linear regression model fit onto one Axes: a scatter of the observations, a fitted line and a bootstrapped confidence band.
Is seaborn regplot the same as sns.regplot?
Yes. sns.regplot is the usual alias form after import seaborn as sns; the function is seaborn.regplot.
How do I remove the confidence interval?
Set ci=None. This also skips the bootstrap, which saves time on large datasets.
How do I get the slope and intercept?
regplot does not return them; it returns the Axes. Compute the fit with a statistics function and report those values.
How do I fit a curve instead of a line?
Use order=2 or higher for a polynomial, or lowess=True for a nonparametric curve with no confidence band.
Can regplot colour points by group?
Not with hue. Use lmplot, which has hue, or draw each group separately onto one Axes.
Sources
- seaborn documentation, seaborn.regplot, read 2026-11-15.
- seaborn documentation, Visualizing regression models, read 2026-11-15.
- seaborn documentation, Installing seaborn, read 2026-11-15.
Data: seaborn.regplot arguments that change the fit, interval or points
Defaults and documented behaviour of twelve seaborn.regplot arguments, compiled from the official seaborn regplot reference page and regression tutorial, with whether the documentation names statsmodels for each.
| Argument | Default | Documented effect | Needs statsmodels per documentation | Documented note |
|---|---|---|---|---|
| ci | 95 | Size of the bootstrapped confidence band around the regression estimate; None skips the bootstrap | Not stated | May be advisable to set None for large datasets |
| n_boot | 1000 | Number of bootstrap resamples used for the interval | Not stated | Raise for final figures |
| order | 1 | Polynomial regression when greater than 1 | No (numpy.polyfit) | |
| logistic | False | Logistic regression for a binary y | Yes | Substantially more computationally intensive |
| lowess | False | Locally weighted nonparametric fit | Yes | No confidence interval can be drawn |
| robust | False | Robust regression that de-weights outliers | Yes | Substantially more computationally intensive |
| logx | False | Fits y ~ log(x), plotted in input space | Not stated | x must be positive |
| truncate | True | Line bounded by data limits; False extends to axis limits | Not stated | Drawing extent only |
| x_jitter | None | Uniform noise added to a copy of the data after fitting | Not stated | Changes scatter appearance only |
| x_bins | None | Bins x for the scatter display; implies x_estimator=numpy.mean | Not stated | Regression still uses the original data |
| x_estimator | None | Function applied to each unique x value | Not stated | Interval bootstrapped when x_ci is set |
| units | None | Multilevel bootstrap grouping | Not stated | Affects confidence intervals only |
Sources
- seaborn.regplot (accessed 2026-11-15)
- Visualizing regression models (accessed 2026-11-15)
Compiled by CASRAI from the sources above. Free to reuse under CC BY 4.0 with attribution.







