seaborn.
lmplot
(x, y, data, hue=None, col=None, row=None, palette=None, col_wrap=None, height=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, size=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. See the tutorial for more information.
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: |
|
---|
See also
Notes
The regplot()
and lmplot()
functions are closely related, but
the former is an axes-level function while the latter is a figure-level
function that combines regplot()
and FacetGrid
.
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 black-and-white 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 height and aspect ratio of the facets:
>>> g = sns.lmplot(x="size", y="total_bill", hue="day", col="day",
... data=tips, height=6, 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, height=3)
Condition on two variables to make a full grid:
>>> g = sns.lmplot(x="total_bill", y="tip", row="sex", col="time",
... data=tips, height=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, height=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))