seaborn.lmplot#
- seaborn.lmplot(data, *, x=None, y=None, hue=None, col=None, row=None, palette=None, col_wrap=None, height=5, aspect=1, markers='o', sharex=None, sharey=None, hue_order=None, col_order=None, row_order=None, legend=True, legend_out=None, x_estimator=None, x_bins=None, x_ci='ci', scatter=True, fit_reg=True, ci=95, n_boot=1000, units=None, seed=None, order=1, logistic=False, lowess=False, robust=False, logx=False, x_partial=None, y_partial=None, truncate=True, x_jitter=None, y_jitter=None, scatter_kws=None, line_kws=None, facet_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 - huefor the most important comparison, followed by- coland- 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:
- dataDataFrame
- Tidy (“long-form”) dataframe where each column is a variable and each row is an observation. 
- x, ystrings, optional
- Input variables; these should be column names in - data.
- hue, col, rowstrings
- Variables that define subsets of the data, which will be drawn on separate facets in the grid. See the - *_orderparameters to control the order of levels of this variable.
- palettepalette name, list, or dict
- Colors to use for the different levels of the - huevariable. Should be something that can be interpreted by- color_palette(), or a dictionary mapping hue levels to matplotlib colors.
- col_wrapint
- “Wrap” the column variable at this width, so that the column facets span multiple rows. Incompatible with a - rowfacet.
- heightscalar
- Height (in inches) of each facet. See also: - aspect.
- aspectscalar
- Aspect ratio of each facet, so that - aspect * heightgives the width of each facet in inches.
- markersmatplotlib marker code or list of marker codes, optional
- Markers for the scatterplot. If a list, each marker in the list will be used for each level of the - huevariable.
- share{x,y}bool, ‘col’, or ‘row’ optional
- If true, the facets will share y axes across columns and/or x axes across rows. - Deprecated since version 0.12.0: Pass using the - facet_kwsdictionary.
- {hue,col,row}_orderlists, optional
- Order for the levels of the faceting variables. By default, this will be the order that the levels appear in - dataor, if the variables are pandas categoricals, the category order.
- legendbool, optional
- If - Trueand there is a- huevariable, add a legend.
- legend_outbool
- If - True, the figure size will be extended, and the legend will be drawn outside the plot on the center right.- Deprecated since version 0.12.0: Pass using the - facet_kwsdictionary.
- x_estimatorcallable that maps vector -> scalar, optional
- Apply this function to each unique value of - xand plot the resulting estimate. This is useful when- xis a discrete variable. If- x_ciis given, this estimate will be bootstrapped and a confidence interval will be drawn.
- x_binsint or vector, optional
- Bin the - xvariable into discrete bins and then estimate the central tendency and a confidence interval. This binning only influences how the scatterplot is drawn; the regression is still fit to the original data. This parameter is interpreted either as the number of evenly-sized (not necessary spaced) bins or the positions of the bin centers. When this parameter is used, it implies that the default of- x_estimatoris- numpy.mean.
- x_ci“ci”, “sd”, int in [0, 100] or None, optional
- Size of the confidence interval used when plotting a central tendency for discrete values of - x. If- "ci", defer to the value of the- ciparameter. If- "sd", skip bootstrapping and show the standard deviation of the observations in each bin.
- scatterbool, optional
- If - True, draw a scatterplot with the underlying observations (or the- x_estimatorvalues).
- fit_regbool, optional
- If - True, estimate and plot a regression model relating the- xand- yvariables.
- ciint in [0, 100] or None, optional
- Size of the confidence interval for the regression estimate. This will be drawn using translucent bands around the regression line. The confidence interval is estimated using a bootstrap; for large datasets, it may be advisable to avoid that computation by setting this parameter to None. 
- n_bootint, optional
- Number of bootstrap resamples used to estimate the - ci. The default value attempts to balance time and stability; you may want to increase this value for “final” versions of plots.
- unitsvariable name in data, optional
- If the - xand- yobservations are nested within sampling units, those can be specified here. This will be taken into account when computing the confidence intervals by performing a multilevel bootstrap that resamples both units and observations (within unit). This does not otherwise influence how the regression is estimated or drawn.
- seedint, numpy.random.Generator, or numpy.random.RandomState, optional
- Seed or random number generator for reproducible bootstrapping. 
- orderint, optional
- If - orderis greater than 1, use- numpy.polyfitto estimate a polynomial regression.
- logisticbool, optional
- If - True, assume that- yis a binary variable and use- statsmodelsto estimate a logistic regression model. Note that this is substantially more computationally intensive than linear regression, so you may wish to decrease the number of bootstrap resamples (- n_boot) or set- cito None.
- lowessbool, optional
- If - True, use- statsmodelsto estimate a nonparametric lowess model (locally weighted linear regression). Note that confidence intervals cannot currently be drawn for this kind of model.
- robustbool, optional
- If - True, use- statsmodelsto estimate a robust regression. This will de-weight outliers. Note that this is substantially more computationally intensive than standard linear regression, so you may wish to decrease the number of bootstrap resamples (- n_boot) or set- cito None.
- logxbool, optional
- If - True, estimate a linear regression of the form y ~ log(x), but plot the scatterplot and regression model in the input space. Note that- xmust be positive for this to work.
- {x,y}_partialstrings in dataor matrices
- Confounding variables to regress out of the - xor- yvariables before plotting.
- truncatebool, optional
- If - True, the regression line is bounded by the data limits. If- False, it extends to the- xaxis limits.
- {x,y}_jitterfloats, optional
- Add uniform random noise of this size to either the - xor- yvariables. The noise is added to a copy of the data after fitting the regression, and only influences the look of the scatterplot. This can be helpful when plotting variables that take discrete values.
- {scatter,line}_kwsdictionaries
- Additional keyword arguments to pass to - plt.scatterand- plt.plot.
- facet_kwsdict
- Dictionary of keyword arguments for - FacetGrid.
 
 - 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 - See the - regplot()docs for demonstrations of various options for specifying the regression model, which are also accepted here.- Plot a regression fit over a scatter plot: - sns.lmplot(data=penguins, x="bill_length_mm", y="bill_depth_mm")   - Condition the regression fit on another variable and represent it using color: - sns.lmplot(data=penguins, x="bill_length_mm", y="bill_depth_mm", hue="species")   - Condition the regression fit on another variable and split across subplots: - sns.lmplot( data=penguins, x="bill_length_mm", y="bill_depth_mm", hue="species", col="sex", height=4, )   - Condition across two variables using both columns and rows: - sns.lmplot( data=penguins, x="bill_length_mm", y="bill_depth_mm", col="species", row="sex", height=3, )   - Allow axis limits to vary across subplots: - sns.lmplot( data=penguins, x="bill_length_mm", y="bill_depth_mm", col="species", row="sex", height=3, facet_kws=dict(sharex=False, sharey=False), ) 