Skip to main content
v2026.11,986 entries · CC-BY 4.0

sns.lmplot: Seaborn Regression Facets Syntax and Examples

Use sns.lmplot to fit and compare regression lines across groups: install, syntax, a worked penguins example, reading the fit and troubleshooting.

Written and maintained by CASRAI Editorial Board

Published

On this page

sns.lmplot is seaborn’s figure-level function for drawing a scatter plot with a fitted regression line, and for repeating that plot across subsets of a dataset. You pass a tidy table with data=, name the x and y columns, and add hue, col or row to fit a separate regression for each level of a third variable. The seaborn documentation describes it as combining regplot with a FacetGrid, so it is the right call when the question is “does this relationship look different in each group?” rather than “what does one fitted line look like?”.

This guide covers what the function does for research analysts, how to install seaborn, a step-by-step worked example on a public dataset, how to read the figure, the errors that most often interrupt a first run, and the free alternatives inside the same Python ecosystem. For the single-axes sibling, see the guide to sns.regplot; for the grid machinery underneath, see seaborn FacetGrid.

What sns.lmplot is used for in research

Researchers reach for lmplot at the exploration stage of an analysis, before or alongside a formal model. It answers a visual question: for two continuous variables, how does the straight-line (or curved) trend change across conditions, cohorts, sites or treatment arms? The seaborn regression tutorial says lmplot is useful for fitting a regression across conditional subsets of a dataset, and that it is a figure-level function that requires the data argument.

It is a plotting tool, not an inference tool. The seaborn tutorial states plainly that seaborn is not itself a package for statistical analysis, and points readers to statsmodels when they need the model’s coefficients, tests and diagnostics. A good working pattern is to use lmplot to see whether the relationship is roughly linear and whether groups behave differently, then fit and report the model in a statistics package. The CASRAI guide to logistic regression in statsmodels shows that second step for binary outcomes, and the guide to linear and multiple regression explains the model itself.

lmplot or regplot?

Both draw a scatter plot with a regression fit, and they accept similar fitting options. The difference, per the seaborn documentation, is that regplot is axes-level and lmplot is figure-level. An axes-level function draws on one matplotlib axes you supply, so you can place it inside a figure you built yourself. A figure-level function creates and manages its own figure, which is what lets it lay out one panel per level of col and row. Choose lmplot when you need facets or a per-group fit; choose regplot when you need one panel inside a larger custom figure.

lmplot or relplot?

The regression tutorial notes a limit of lmplot: it cannot map a separate variable to scatter-style properties the way relplot can. If you need marker size or marker style to carry its own variable, draw the scatter with relplot and handle the fit separately.

How to install or access seaborn

The official installation page gives these routes. With pip:

pip install seaborn

To also install the optional statistical dependencies in the same step:

pip install seaborn[stats]

With conda, from the conda-forge channel:

conda install seaborn -c conda-forge

Seaborn depends on numpy, pandas and matplotlib. The installation page lists statsmodels as an optional dependency for advanced regression plots, and scipy as optional too. That matters for lmplot because several of its fitting options (logistic, robust and lowess among them) are the “advanced” cases. If you plan to use them, install the stats extra up front. The usual import is:

import seaborn as sns
import matplotlib.pyplot as plt

How to draw a faceted regression with sns.lmplot step by step

The steps below follow the examples in the seaborn lmplot reference, which use the penguins dataset that ships with seaborn’s example data. Substitute your own tidy dataframe, with one row per observation and one column per variable, in your analysis.

  1. Load a tidy dataframe. penguins = sns.load_dataset("penguins"). Every column you name later must exist in this table.
  2. Draw the pooled fit. sns.lmplot(data=penguins, x="bill_length_mm", y="bill_depth_mm") gives one scatter and one fitted line for all rows. This is the baseline you compare the group fits against.
  3. Add a hue to fit one line per group. sns.lmplot(data=penguins, x="bill_length_mm", y="bill_depth_mm", hue="species") colours the points by species and fits a separate regression for each level, on the same axes.
  4. Split into columns. sns.lmplot(data=penguins, x="bill_length_mm", y="bill_depth_mm", hue="species", col="sex", height=4) adds one panel for each level of sex. height sets the size of each facet in inches.
  5. Cross two variables. sns.lmplot(data=penguins, x="bill_length_mm", y="bill_depth_mm", col="species", row="sex", height=3) draws a grid with one column per species and one row per sex.
  6. Free the axes if the groups sit on different scales. sns.lmplot(data=penguins, x="bill_length_mm", y="bill_depth_mm", col="species", facet_kws=dict(sharex=False, sharey=False)). The reference documents that sharex, sharey and legend_out were deprecated as direct arguments in version 0.12.0 and should be passed through facet_kws.
  7. Show the figure. In a script, call plt.show(); in a notebook the figure renders when the cell finishes.

Arguments that change the fit

The data table below lists the fitting and layout arguments, with their defaults and effects, as given in the signature and parameter descriptions of the seaborn reference. Three behaviours are easy to miss. First, x_bins and the jitter arguments affect only how the points are displayed: the seaborn reference says binning changes the scatter display and not the fit, and that jitter is added after fitting. Second, order above 1 fits a polynomial using numpy’s polyfit. Third, units triggers a multilevel bootstrap for the confidence band and does not change the fitted line.

Layout rules for col, row and col_wrap

col_wrap wraps a single column variable across several rows of panels, which suits a variable with many levels. The reference states it is incompatible with row, so use one or the other. Panel width is aspect multiplied by height, with height in inches and aspect defaulting to 1 (a square panel at the default height of 5).

How to read the output

Each panel shows the observations as points and the fitted regression as a line with a shaded band. By default the band is a 95% confidence interval (ci=95) estimated by bootstrapping with 1,000 resamples (n_boot=1000). Set ci=None to remove the band; the regression tutorial suggests this to speed up iteration while you are still adjusting the layout.

When you read a faceted plot, compare these things panel by panel:

  • Slope direction and steepness. If the pooled line and the group lines point in different directions, the pooled line is summarising a mixture and should not be reported as if it described each group.
  • Band width. A wide band in one panel usually reflects few points or high scatter there. Do not read two lines as different if their bands overlap heavily.
  • Line length. With the default truncate=True the line spans only the range of the data in that panel; set truncate=False to extend it to the axis limits, and treat any extension as extrapolation.
  • Fit shape. A straight line forced through curved data misleads. The tutorial uses Anscombe’s quartet to show datasets with near-identical linear fits and very different structure, and shows residplot, where random scatter around zero suggests a linear model is reasonable.

The figure gives you no coefficients, standard errors or p-values. To report those, fit the same model in statsmodels and cite that output, not the picture.

Troubleshooting sns.lmplot

The call raises an error about arguments

The current signature is lmplot(data, *, x, y, hue, col, row, ...). The asterisk means x, y and every other option after data must be passed by keyword. Code copied from older tutorials may use positional arguments or arguments absent from the current signature; the signature has no size parameter, so use height and aspect for panel dimensions.

Passing col_wrap together with row

This combination is documented as incompatible. Drop row and use col_wrap, or drop col_wrap and keep the col by row grid.

Deprecation warnings for sharex, sharey or legend_out

These three were deprecated as direct arguments in 0.12.0. Move them into facet_kws=dict(...).

A lowess fit has no confidence band

With lowess=True the reference notes there is no confidence interval. This is expected behaviour, not a failure to draw.

logistic or robust fits are slow or fail to import

The reference describes the logistic and robust fits as computationally intensive and as requiring statsmodels. Install statsmodels (or seaborn[stats]) and consider ci=None while you iterate.

logx fails

logx=True fits the model on the logarithm of x, so every x value must be greater than zero. Filter or transform the data first, and say in your methods text that the fit is on a log scale.

Binning or jitter seems to change the story

It should not change the fit. x_bins only changes how the scatter points are drawn, and jitter is added after fitting for display. If the line moves, you changed another argument.

Free alternatives to sns.lmplot

The alternatives below stay inside the open-source Python scientific stack that seaborn itself depends on or documents. Each row is taken from the seaborn documentation and tutorial pages listed under Sources.

Alternative When it fits better than lmplot
seaborn.regplot You want one regression drawn on a matplotlib axes of your own. The seaborn docs describe it as axes-level and lmplot as figure-level.
seaborn.pairplot with kind="reg" You want regression fits across many pairs of variables in one grid rather than facets of a single pair.
seaborn.residplot You want to check the linearity assumption: random scatter around zero suggests a linear fit is reasonable.
seaborn.relplot You need marker size or style to encode extra variables, which lmplot cannot do.
statsmodels You need coefficients, tests and diagnostics, which seaborn does not provide.

For the facet machinery on its own, with any plot type, see seaborn FacetGrid; to compare groups’ distributions rather than regressions, see the guide to seaborn histograms.

Reporting a regression figure in a paper

Because lmplot shows the fit but not its statistics, a figure built with it needs a caption that states what the line is. Name the fit (ordinary least squares, polynomial of a stated order, lowess, logistic or robust), say what the shaded band is (95% bootstrap confidence interval with 1,000 resamples under the defaults), and note any transformation such as logx. Give the coefficients and uncertainty in the text or a table from a statistics package. If you use the hue or facet split to argue that groups differ, support that claim with a formal test of the interaction rather than the visual contrast alone.

Sources

Data: sns.lmplot arguments that control fit, uncertainty and facet layout

Compiled from the parameter list and parameter descriptions of the seaborn lmplot reference page and the seaborn regression tutorial: each fitting or layout argument with its default, its documented effect and any documented requirement or limitation. Defaults and notes are as stated on the seaborn documentation pages checked on 2026-11-18.

sns.lmplot arguments that control fit, uncertainty and facet layout
ArgumentDefaultDocumented effectRequirement or limitation
col_wrapnoneWraps the col variable across several rows of panelsIncompatible with row
height5Size of each facet in inchesFacet width = aspect x height
aspect1Width-to-height ratio of each facetDefault gives square panels
order1Polynomial order of the fitOrders above 1 use numpy.polyfit
logisticFalseFits a logistic regression for a binary yRequires statsmodels; computationally intensive
lowessFalseFits a locally weighted smoother instead of a lineNo confidence interval is drawn
robustFalseFits a robust regression that down-weights outliersRequires statsmodels; computationally intensive
logxFalseFits the model on log(x)All x values must be greater than 0
x_binsnoneBins x for display of the pointsChanges only the scatter display, not the fit
x_jitter / y_jitternoneAdds random noise to pointsApplied after fitting; display only
ci95Confidence level of the bootstrap band; None removes itRelated: n_boot defaults to 1000
unitsnoneSampling units for a multilevel bootstrapDoes not change the fitted line
truncateTrueLine spans only the range of the dataFalse extends it to the axis limits
facet_kwsnoneDict passed to the underlying FacetGrid, for example sharex=FalseDirect sharex, sharey, legend_out deprecated since 0.12.0

Sources

Compiled by CASRAI from the sources above. Free to reuse under CC BY 4.0 with attribution.

Follow CASRAI

Research-administration guidance, standards updates and independent tool reviews.

Ask CASRAI · full access

Ask about sns.lmplot: Seaborn Regression Facets Syntax and Examples

Full access: large monthly usage, up to 10 source passages behind each answer, and MCP and API access for Claude Code, Codex and other CLIs. Cancel any time.

An AI assistant for research: funder rules, compliance, methods and publishing. It links the sources behind its answers and labels answers that come from a web search.

Answers draw on CASRAI's guides and dictionary plus the federal and funder documents we index: Federal Register, Grants.gov, Regulations.gov and UKRI.

Works on this site and inside Claude, Cursor and the AI tools you already use.

Everything CASRAI publishes — this page, the dictionary, the guides and the news — stays open to read, with no account and no card.

Referenced across the research world

University of Cambridge logoColumbia University logoCrossref logoUniversity of Edinburgh logoHarvard University logoUniversity of Oxford logoPrinceton University logoStanford School of Medicine logoUniversity College London logoORCID logoUniversity of Cambridge logoColumbia University logoCrossref logoUniversity of Edinburgh logoHarvard University logoUniversity of Oxford logoPrinceton University logoStanford School of Medicine logoUniversity College London logoORCID logo
  • University of Cambridge logo
  • Columbia University logo
  • Crossref logo
  • University of Edinburgh logo
  • Harvard University logo
  • University of Oxford logo
  • Princeton University logo
  • Stanford School of Medicine logo
  • University College London logo
  • ORCID logo

View CASRAI adoption →