Regression line plot

Seaborn basics

2 min read

Published Oct 7 2025


24
0
0
0

ChartsGraphsMatplotlibNumPyPandasPythonSeabornVisualisation

seaborn.regplot() plots data points (scatter) along with a regression line (best-fit line).
It is an axes-level function (draws on a single subplot).

It’s mainly used to visualise the relationship between two numeric variables, showing both the trend (linear regression) and the data spread.


Syntax:

sns.regplot(
    data=None,
    *,
    x=None,
    y=None,
    x_estimator=None,
    x_bins=None,
    x_ci='ci',
    scatter=True,
    fit_reg=True,
    order=1,
    robust=False,
    logx=False,
    ci=95,
    n_boot=1000,
    seed=None,
    line_kws=None,
    scatter_kws=None,
    color=None,
    marker='o',
    ax=None,
    **kwargs
)

Parameters:

  • data = DataFrame containing the data
  • x, y = Numeric variables for regression
  • scatter = If True, shows scatter points
  • fit_reg = If True, draws regression line
  • order = Degree of polynomial (1 = linear)
  • robust = Use robust regression (less sensitive to outliers)
  • logx = If True, log-transform the x-axis
  • ci = Confidence interval around regression line (in %)
  • line_kws = Dictionary of keyword args for the line (e.g., colour, linestyle)
  • scatter_kws = Dictionary of keyword args for scatter points
  • color = Base colour for both scatter and line
  • ax = Axis to plot on (for subplot use)




Basic example

import seaborn as sns
import matplotlib.pyplot as plt

tips = sns.load_dataset("tips")

sns.regplot(data=tips, x="total_bill", y="tip")
plt.show()

Plots a scatterplot with a best-fit linear regression line. The shaded area shows the 95% confidence interval.


seaborn reg plot basic example





Turn off scatter or line


Line Only:

import seaborn as sns
import matplotlib.pyplot as plt

tips = sns.load_dataset("tips")

sns.regplot(data=tips, x="total_bill", y="tip", scatter=False)
plt.show()

Shows only the regression line.


seaborn reg plot line only example


Scatter Only:

import seaborn as sns
import matplotlib.pyplot as plt

tips = sns.load_dataset("tips")

sns.regplot(data=tips, x="total_bill", y="tip", fit_reg=False)
plt.show()

Shows only the scatter points (same as sns.scatterplot()).


seaborn reg plot scatter only example





Change line appearance

import seaborn as sns
import matplotlib.pyplot as plt

tips = sns.load_dataset("tips")

sns.regplot(
    data=tips,
    x="total_bill",
    y="tip",
    line_kws={"color": "red", "linestyle": "--", "linewidth": 2}
)
plt.show()

Customises line colour, style, and width.


seaborn reg plot custom line example





Add scatter customisation

import seaborn as sns
import matplotlib.pyplot as plt

tips = sns.load_dataset("tips")

sns.regplot(
    data=tips,
    x="total_bill",
    y="tip",
    scatter_kws={"s": 80, "alpha": 0.6, "color": "green"}
)
plt.show()

Adjusts point size (s), transparency (alpha), and colour.


seaborn reg plot scatter customise example





Polynomial regression (nonlinear)

import seaborn as sns
import matplotlib.pyplot as plt

tips = sns.load_dataset("tips")

sns.regplot(data=tips, x="total_bill", y="tip", order=2, color="purple")
plt.show()

Fits a 2nd-degree polynomial (curve instead of straight line). You can use higher orders (e.g., order=3) for more curvature.


seaborn reg plot polynomial example





Robust regression

import seaborn as sns
import matplotlib.pyplot as plt

tips = sns.load_dataset("tips")

sns.regplot(data=tips, x="total_bill", y="tip", robust=True)
plt.show()

Uses a robust estimator to reduce the effect of outliers on the regression line.


seaborn reg plot robust example





Logarithmic x-axis

import seaborn as sns
import matplotlib.pyplot as plt

tips = sns.load_dataset("tips")

sns.regplot(data=tips, x="total_bill", y="tip", logx=True)
plt.show()

Applies a log transformation to the x-axis — useful for skewed data.


seaborn reg plot log example





Change confidence interval

import seaborn as sns
import matplotlib.pyplot as plt

tips = sns.load_dataset("tips")

sns.regplot(data=tips, x="total_bill", y="tip", ci=68)
plt.show()

Shows a 68% confidence interval instead of the default 95%. Set ci=None to remove the shaded band completely.


seaborn reg plot ci example





Binned regression (x_bins)

import seaborn as sns
import matplotlib.pyplot as plt

tips = sns.load_dataset("tips")

sns.regplot(data=tips, x="total_bill", y="tip", x_bins=10)
plt.show()

Groups data along the x-axis into bins, showing average y-values for each bin. Useful for very large datasets or when data are not evenly distributed.


seaborn reg plot binned example





Weighted regression (x_estimator)

import seaborn as sns
import matplotlib.pyplot as plt
import numpy as np

tips = sns.load_dataset("tips")

sns.regplot(data=tips, x="total_bill", y="tip", x_estimator=np.mean)
plt.show()

Aggregates y values within x bins (using mean, median, etc.) before fitting the line.


seaborn reg plot x estimator example





Customise colors and markers

import seaborn as sns
import matplotlib.pyplot as plt

tips = sns.load_dataset("tips")

sns.regplot(
    data=tips,
    x="total_bill",
    y="tip",
    color="teal",
    marker="x",
    line_kws={"color": "orange"}
)
plt.show()

Marker and line customised separately.


seaborn reg plot style sep example





Combine with other plots

Example — regression line on top of a histogram of x:

import seaborn as sns
import matplotlib.pyplot as plt

tips = sns.load_dataset("tips")

sns.histplot(data=tips, x="total_bill", bins=20, color="lightgray")
sns.regplot(data=tips, x="total_bill", y="tip", scatter=False, color="red")
plt.show()

Regression line overlays a histogram background.


seaborn reg plot with histogram example
© 2025 SimpleSteps.guide
AboutFAQPoliciesContact