seaborn.
lmplot
(x, y, data, hue=None, col=None, row=None, palette=None, col_wrap=None, size=5, aspect=1, markers='o', sharex=True, sharey=True, hue_order=None, col_order=None, row_order=None, legend=True, legend_out=True, 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, x_jitter=None, y_jitter=None, scatter_kws=None, line_kws=None)¶Plot data and regression model fits across a FacetGrid.
This function combines regplot()
and FacetGrid
. It is
intended as a convenient interface to fit regression models across
conditional subsets of a dataset.
When thinking about how to assign variables to different facets, a general
rule is that it makes sense to use hue
for the most important
comparison, followed by col
and row
. However, always think about
your particular dataset and the goals of the visualization you are
creating.
There are a number of mutually exclusive options for estimating the
regression model: order
, logistic
, lowess
, robust
, and
logx
. See the parameter docs for more information on these options.
The parameters to this function span most of the options in
FacetGrid
, although there may be occasional cases where you will
want to use that class and regplot()
directly.
Parameters:  x, y : strings, optional
data : DataFrame
hue, col, row : strings
palette : seaborn color palette or dict, optional
col_wrap : int, optional
size : scalar, optional
aspect : scalar, optional
markers : matplotlib marker code or list of marker codes, optional
share{x,y} : bool, optional
{hue,col,row}_order : lists, optional
legend : bool, optional
legend_out : bool, optional
x_estimator : callable that maps vector > scalar, optional
x_bins : int or vector, optional
x_ci : “ci”, “sd”, int in [0, 100] or None, optional
scatter : bool, optional
fit_reg : bool, optional
ci : int in [0, 100] or None, optional
n_boot : int, optional
units : variable name in
order : int, optional
logistic : bool, optional
lowess : bool, optional
robust : bool, optional
logx : bool, optional
{x,y}_partial : strings in
truncate : bool, optional
{x,y}_jitter : floats, optional
{scatter,line}_kws : dictionaries


See also
Notes
Understanding the difference between regplot()
and lmplot()
can
be a bit tricky. In fact, they are closely related, as lmplot()
uses
regplot()
internally and takes most of its parameters. However,
regplot()
is an axeslevel function, so it draws directly onto an
axes (either the currently active axes or the one provided by the ax
parameter), while lmplot()
is a figurelevel function and creates its
own figure, which is managed through a FacetGrid
. This has a few
consequences, namely that regplot()
can happily coexist in a figure
with other kinds of plots and will follow the global matplotlib color
cycle. In contrast, lmplot()
needs to occupy an entire figure, and
the size and color cycle are controlled through function parameters,
ignoring the global defaults.
Examples
These examples focus on basic regression model plots to exhibit the
various faceting options; see the regplot()
docs for demonstrations
of the other options for plotting the data and models. There are also
other examples for how to manipulate plot using the returned object on
the FacetGrid
docs.
Plot a simple linear relationship between two variables:
>>> import seaborn as sns; sns.set(color_codes=True)
>>> tips = sns.load_dataset("tips")
>>> g = sns.lmplot(x="total_bill", y="tip", data=tips)
Condition on a third variable and plot the levels in different colors:
>>> g = sns.lmplot(x="total_bill", y="tip", hue="smoker", data=tips)
Use different markers as well as colors so the plot will reproduce to blackandwhite more easily:
>>> g = sns.lmplot(x="total_bill", y="tip", hue="smoker", data=tips,
... markers=["o", "x"])
Use a different color palette:
>>> g = sns.lmplot(x="total_bill", y="tip", hue="smoker", data=tips,
... palette="Set1")
Map hue
levels to colors with a dictionary:
>>> g = sns.lmplot(x="total_bill", y="tip", hue="smoker", data=tips,
... palette=dict(Yes="g", No="m"))
Plot the levels of the third variable across different columns:
>>> g = sns.lmplot(x="total_bill", y="tip", col="smoker", data=tips)
Change the size and aspect ratio of the facets:
>>> g = sns.lmplot(x="size", y="total_bill", hue="day", col="day",
... data=tips, aspect=.4, x_jitter=.1)
Wrap the levels of the column variable into multiple rows:
>>> g = sns.lmplot(x="total_bill", y="tip", col="day", hue="day",
... data=tips, col_wrap=2, size=3)
Condition on two variables to make a full grid:
>>> g = sns.lmplot(x="total_bill", y="tip", row="sex", col="time",
... data=tips, size=3)
Use methods on the returned FacetGrid
instance to further tweak
the plot:
>>> g = sns.lmplot(x="total_bill", y="tip", row="sex", col="time",
... data=tips, size=3)
>>> g = (g.set_axis_labels("Total bill (US Dollars)", "Tip")
... .set(xlim=(0, 60), ylim=(0, 12),
... xticks=[10, 30, 50], yticks=[2, 6, 10])
... .fig.subplots_adjust(wspace=.02))