LM - Linear Model plot

Seaborn basics

2 min read

Published Oct 7 2025


24
0
0
0

ChartsGraphsMatplotlibNumPyPandasPythonSeabornVisualisation

seaborn.lmplot() plots data points (scatter) along with a linear regression model fit, just like sns.regplot().
However, unlike regplot(), lmplot() is a figure-level function, meaning it can create:

  • Multiple subplots (facets) based on categorical variables
  • Grouped regressions using color (hue)

It’s built on top of sns.regplot() and adds faceting (via FacetGrid) for multi-group or multi-category analysis.


Syntax:

sns.lmplot(
    data=None,
    *,
    x=None,
    y=None,
    hue=None,
    col=None,
    row=None,
    palette=None,
    col_wrap=None,
    height=5,
    aspect=1,
    markers=None,
    scatter=True,
    fit_reg=True,
    ci=95,
    n_boot=1000,
    order=1,
    robust=False,
    logx=False,
    truncate=True,
    x_estimator=None,
    x_bins=None,
    line_kws=None,
    scatter_kws=None,
    legend=True,
    legend_out=True,
    facet_kws=None,
    **kwargs
)

Parameters:

  • data = DataFrame containing the data
  • x, y = Numeric variables for regression
  • hue = Adds subgroups (different colours and regression lines)
  • col, row = Facet the data into multiple subplots
  • palette = Colour palette for hue groups
  • col_wrap = Wrap facet columns into multiple rows
  • height = Height (in inches) of each facet
  • aspect = Aspect ratio (width/height) of each facet
  • order = Degree of polynomial regression (1 = linear)
  • robust = Use robust regression to reduce outlier influence
  • ci = Confidence interval width (in %)
  • line_kws = Keyword args for line (colour, style, width, etc.)
  • scatter_kws = Keyword args for scatter points
  • legend = Show/hide legend
  • legend_out = Place legend outside the plot grid
  • facet_kws = Pass additional parameters to the FacetGrid




Basic example

import seaborn as sns
import matplotlib.pyplot as plt

tips = sns.load_dataset("tips")

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

Plots a scatterplot with a regression line and 95% confidence interval. Figure-level → creates its own figure and axes.


seaborn lm plot basic example





Facet into multiple columns

import seaborn as sns
import matplotlib.pyplot as plt

tips = sns.load_dataset("tips")

sns.lmplot(data=tips, x="total_bill", y="tip", col="day")
plt.show()

Creates one subplot per day. Each shows its own scatter + regression line.


seaborn lm plot col example





Facet by rows and columns

import seaborn as sns
import matplotlib.pyplot as plt

tips = sns.load_dataset("tips")

sns.lmplot(data=tips, x="total_bill", y="tip", col="day", row="sex")
plt.show()

Creates a grid of subplots, split by both day (columns) and sex (rows).


seaborn lm plot rows col example





Wrap columns across rows

import seaborn as sns
import matplotlib.pyplot as plt

tips = sns.load_dataset("tips")

sns.lmplot(
    data=tips,
    x="total_bill",
    y="tip",
    col="day",
    col_wrap=2,
    height=4
)
plt.show()

Creates 2 columns per row (better layout for many facets).


seaborn lm plot wrap example





Compare groups side-by-side

import seaborn as sns
import matplotlib.pyplot as plt

tips = sns.load_dataset("tips")

sns.lmplot(
    data=tips,
    x="total_bill",
    y="tip",
    hue="sex",
    col="day",
    palette="Set2"
)
plt.show()

Multiple regression lines across columns for day, coloured by sex.


seaborn lm plot col hue example
© 2025 SimpleSteps.guide
AboutFAQPoliciesContact