Draw a categorical scatterplot with non-overlapping points.
绘制具有非重叠点的分类散点图。
This function is similar to [`stripplot()`](seaborn.stripplot.html#seaborn.stripplot"seaborn.stripplot"), but the points are adjusted (only along the categorical axis) so that they don’t overlap. This gives a better representation of the distribution of values, but it does not scale well to large numbers of observations. This style of plot is sometimes called a “beeswarm”.
A swarm plot can be drawn on its own, but it is also a good complement to a box or violin plot in cases where you want to show all observations along with some representation of the underlying distribution.
Arranging the points properly requires an accurate transformation between data and point coordinates. This means that non-default axis limits must be set _before_ drawing the plot.
正确排列点需要在数据和点坐标之间进行精确转换。这意味着必须在绘制绘图之前设置非默认轴限制。
Input data can be passed in a variety of formats, including:
输入数据可以以多种格式传递,包括:
* 表示为列表,numpy arrays或pandas Series objects直接传递给`x`,`y`和/或`hue`参数。
* “长格式” DataFrame, `x`,`y`和`hue`变量将决定数据的绘制方式
* “宽格式”DataFrame,用于绘制每个数字列。
* 一个数组或向量列表。
* Vectors of data represented as lists, numpy arrays, or pandas Series objects passed directly to the `x`, `y`, and/or `hue` parameters.
* A “long-form” DataFrame, in which case the `x`, `y`, and `hue` variables will determine how the data are plotted.
* A “wide-form” DataFrame, such that each numeric column will be plotted.
In most cases, it is possible to use numpy or Python objects, but pandas objects are preferable because the associated names will be used to annotate the axes. Additionally, you can use Categorical types for the grouping variables to control the order of plot elements.
This function always treats one of the variables as categorical and draws data at ordinal positions (0, 1, … n) on the relevant axis, even when the data has a numeric or date type.
> When using `hue` nesting, setting this to `True` will separate the strips for different hue levels along the categorical axis. Otherwise, the points for each level will be plotted in one swarm.
> Orientation of the plot (vertical or horizontal). This is usually inferred from the dtype of the input variables, but can be used to specify when the “categorical” variable is a numeric or when plotting wide-form data.
`color`:matplotlib color, 可选
`color`:matplotlib color, optional
> 所有元素的颜色,或渐变调色板的种子。
> Color for all of the elements, or seed for a gradient palette.
> Colors to use for the different levels of the `hue` variable. Should be something that can be interpreted by [`color_palette()`](seaborn.color_palette.html#seaborn.color_palette "seaborn.color_palette"), or a dictionary mapping hue levels to matplotlib colors.
> Diameter of the markers, in points. (Although `plt.scatter` is used to draw the points, the `size` argument here takes a “normal” markersize and not size^2 like `plt.scatter`.
`edgecolor`:matplotlib color, “灰色”是特殊的,可选
`edgecolor`:matplotlib color, “gray” is special-cased, optional
> 每个点周围线条的颜色。如果传递`"gray"`,则亮度由用于点体的调色板决定。
> Color of the lines around each point. If you pass `"gray"`, the brightness is determined by the color palette used for the body of the points.
`linewidth`:float, 可选
`linewidth`:float, optional
> 构图元素的灰线宽度。
> Width of the gray lines that frame the plot elements.
`ax`:matplotlib Axes, 可选
`ax`:matplotlib Axes, optional
> Axes object to draw the plot onto, otherwise uses the current Axes.
> Axes对象将绘图绘制到,否则使用当前轴。
返回值:`ax`:matplotlib Axes
> Returns the Axes object with the plot drawn onto it.
> 返回Axes对象,并在其上绘制绘图。
See also
参看
A traditional box-and-whisker plot with a similar API.A combination of boxplot and kernel density estimation.A scatterplot where one variable is categorical. Can be used in conjunction with other plots to show each observation.Combine a categorical plot with a class:<cite>FacetGrid</cite>.
Use [`catplot()`](seaborn.catplot.html#seaborn.catplot"seaborn.catplot") to combine a [`swarmplot()`](#seaborn.swarmplot"seaborn.swarmplot") and a [`FacetGrid`](seaborn.FacetGrid.html#seaborn.FacetGrid"seaborn.FacetGrid"). This allows grouping within additional categorical variables. Using [`catplot()`](seaborn.catplot.html#seaborn.catplot"seaborn.catplot") is safer than using [`FacetGrid`](seaborn.FacetGrid.html#seaborn.FacetGrid"seaborn.FacetGrid") directly, as it ensures synchronization of variable order across facets:
This style of plot was originally named a “letter value” plot because it shows a large number of quantiles that are defined as “letter values”. It is similar to a box plot in plotting a nonparametric representation of a distribution in which all features correspond to actual observations. By plotting more quantiles, it provides more information about the shape of the distribution, particularly in the tails. For a more extensive explanation, you can read the paper that introduced the plot:
In most cases, it is possible to use numpy or Python objects, but pandas objects are preferable because the associated names will be used to annotate the axes. Additionally, you can use Categorical types for the grouping variables to control the order of plot elements.
This function always treats one of the variables as categorical and draws data at ordinal positions (0, 1, … n) on the relevant axis, even when the data has a numeric or date type.
参数:`x, y, hue`:names of variables in `data` or vector data, optional
参数:`x, y, hue`:`data`或向量数据中的变量名称,可选
> Inputs for plotting long-form data. See examples for interpretation.
> 用于绘制长格式数据的输入。查看样例以进一步理解。
`data`:DataFrame, array, or list of arrays, optional
`data`:DataFrame,数组,数组列表,可选
> Dataset for plotting. If `x` and `y` are absent, this is interpreted as wide-form. Otherwise it is expected to be long-form.
> 用于绘图的数据集。如果`x`和`y`都缺失,那么数据将被视为宽格式。否则数据被视为长格式。
`order, hue_order`:lists of strings, optional
`order, hue_order`:字符串列表,可选
> Order to plot the categorical levels in, otherwise the levels are inferred from the data objects.
> 控制分类变量(对应的条形图)的绘制顺序,若缺失则从数据中推断分类变量的顺序。
`orient`:“v” | “h”, optional
`orient`:“v” | “h”,可选
> Orientation of the plot (vertical or horizontal). This is usually inferred from the dtype of the input variables, but can be used to specify when the “categorical” variable is a numeric or when plotting wide-form data.
> Color for all of the elements, or seed for a gradient palette.
> 所有元素的颜色,或渐变调色板的种子颜色。
`palette`:palette name, list, or dict, optional
`palette`:调色板名称,列表或字典,可选
> Colors to use for the different levels of the `hue` variable. Should be something that can be interpreted by [`color_palette()`](seaborn.color_palette.html#seaborn.color_palette "seaborn.color_palette"), or a dictionary mapping hue levels to matplotlib colors.
> Proportion of the original saturation to draw colors at. Large patches often look better with slightly desaturated colors, but set this to `1` if you want the plot colors to perfectly match the input color spec.
> The number of boxes, and by extension number of percentiles, to draw. All methods are detailed in Wickham’s paper. Each makes different assumptions about the number of outliers and leverages different statistical properties.
> Method to use for the width of the letter value boxes. All give similar results visually. “linear” reduces the width by a constant linear factor, “exponential” uses the proportion of data not covered, “area” is proportional to the percentage of data covered.
> Proportion of data believed to be outliers. Used in conjunction with k_depth to determine the number of percentiles to draw. Defaults to 0.007 as a proportion of outliers. Should be in range [0, 1].
Use [`catplot()`](seaborn.catplot.html#seaborn.catplot"seaborn.catplot") to combine [`boxenplot()`](#seaborn.boxenplot"seaborn.boxenplot") and a [`FacetGrid`](seaborn.FacetGrid.html#seaborn.FacetGrid"seaborn.FacetGrid"). This allows grouping within additional categorical variables. Using [`catplot()`](seaborn.catplot.html#seaborn.catplot"seaborn.catplot") is safer than using [`FacetGrid`](seaborn.FacetGrid.html#seaborn.FacetGrid"seaborn.FacetGrid") directly, as it ensures synchronization of variable order across facets:
Show point estimates and confidence intervals using scatter plot glyphs.
通过绘制散点连线显示数据点的估计值和置信区间。
A point plot represents an estimate of central tendency for a numeric variable by the position of scatter plot points and provides some indication of the uncertainty around that estimate using error bars.
点图代表散点图位置的数值变量的中心趋势估计,并使用误差线提供关于该估计的不确定性的一些指示。
Point plots can be more useful than bar plots for focusing comparisons between different levels of one or more categorical variables. They are particularly adept at showing interactions: how the relationship between levels of one categorical variable changes across levels of a second categorical variable. The lines that join each point from the same `hue` level allow interactions to be judged by differences in slope, which is easier for the eyes than comparing the heights of several groups of points or bars.
It is important to keep in mind that a point plot shows only the mean (or other estimator) value, but in many cases it may be more informative to show the distribution of values at each level of the categorical variables. In that case, other approaches such as a box or violin plot may be more appropriate.
In most cases, it is possible to use numpy or Python objects, but pandas objects are preferable because the associated names will be used to annotate the axes. Additionally, you can use Categorical types for the grouping variables to control the order of plot elements.
This function always treats one of the variables as categorical and draws data at ordinal positions (0, 1, … n) on the relevant axis, even when the data has a numeric or date type.
`estimator`:callable that maps vector -> scalar, optional
`estimator`:调用函数实现向量 -> 标量的映射,可选
> Statistical function to estimate within each categorical bin.
> 在每个分箱内进行估计的统计函数。
`ci`:float or “sd” or None, optional
`ci`:float 或 “sd” 或 None,可选
> Size of confidence intervals to draw around estimated values. If “sd”, skip bootstrapping and draw the standard deviation of the observations. If `None`, no bootstrapping will be performed, and error bars will not be drawn.
> Number of bootstrap iterations to use when computing confidence intervals.
> 计算置信区间时使用的引导迭代次数。
`units`:name of variable in `data` or vector data, optional
`units`:`data` 或vector data中变量的名称,可选
> Identifier of sampling units, which will be used to perform a multilevel bootstrap and account for repeated measures design.
> 采样单元的标识符,用于执行多级引导过程(计算置信区间等)并能够处理重复测量的设定。
`markers`:string or list of strings, optional
`markers`:字符串或字符串列表,可选
> Markers to use for each of the `hue` levels.
> 用于每个`hue`色调的级别的标记。
`linestyles`:string or list of strings, optional
`linestyles`:字符串或字符串列表,可选
> Line styles to use for each of the `hue` levels.
> 用于每个`hue`色调的级别的线条风格。
`dodge`:bool or float, optional
`dodge`:bool或float,可选
> Amount to separate the points for each level of the `hue` variable along the categorical axis.
> 用于沿着分类轴分离`hue`变量的每个级别数据点的数量。
`join`:bool, optional
`join`:bool,可选
> If `True`, lines will be drawn between point estimates at the same `hue` level.
> 如果为`True`,则在`hue`级别相同的点估计值之间绘制线条。
`scale`:float, optional
`scale`:float,可选
> Scale factor for the plot elements.
> 绘图元素的比例因子。
`orient`:“v” | “h”, optional
`orient`:“v” | “h”,可选
> Orientation of the plot (vertical or horizontal). This is usually inferred from the dtype of the input variables, but can be used to specify when the “categorical” variable is a numeric or when plotting wide-form data.
> Color for all of the elements, or seed for a gradient palette.
> 所有元素的颜色,或渐变调色板的种子颜色。
`palette`:palette name, list, or dict, optional
`palette`:调色板名称,列表或字典,可选
> Colors to use for the different levels of the `hue` variable. Should be something that can be interpreted by [`color_palette()`](seaborn.color_palette.html#seaborn.color_palette "seaborn.color_palette"), or a dictionary mapping hue levels to matplotlib colors.
Use [`catplot()`](seaborn.catplot.html#seaborn.catplot"seaborn.catplot") to combine a [`barplot()`](seaborn.barplot.html#seaborn.barplot"seaborn.barplot") and a [`FacetGrid`](seaborn.FacetGrid.html#seaborn.FacetGrid"seaborn.FacetGrid"). This allows grouping within additional categorical variables. Using [`catplot()`](seaborn.catplot.html#seaborn.catplot"seaborn.catplot") is safer than using [`FacetGrid`](seaborn.FacetGrid.html#seaborn.FacetGrid"seaborn.FacetGrid") directly, as it ensures synchronization of variable order across facets:
Show point estimates and confidence intervals as rectangular bars.
条形图以矩形条的方式展示数据的点估值和置信区间
A bar plot represents an estimate of central tendency for a numeric variable with the height of each rectangle and provides some indication of the uncertainty around that estimate using error bars. Bar plots include 0 in the quantitative axis range, and they are a good choice when 0 is a meaningful value for the quantitative variable, and you want to make comparisons against it.
For datasets where 0 is not a meaningful value, a point plot will allow you to focus on differences between levels of one or more categorical variables.
对于数据集中的0值没有实际意义的情况,散点图可以让您专注于一个或多个分类变量之间的差异。
It is also important to keep in mind that a bar plot shows only the mean (or other estimator) value, but in many cases it may be more informative to show the distribution of values at each level of the categorical variables. In that case, other approaches such as a box or violin plot may be more appropriate.
In most cases, it is possible to use numpy or Python objects, but pandas objects are preferable because the associated names will be used to annotate the axes. Additionally, you can use Categorical types for the grouping variables to control the order of plot elements.
This function always treats one of the variables as categorical and draws data at ordinal positions (0, 1, … n) on the relevant axis, even when the data has a numeric or date type.
> Order to plot the categorical levels in, otherwise the levels are inferred from the data objects.
> 绘制类别变量的顺序,如果没有,则从数据对象中推断绘图顺序。
`estimator`:callable that maps vector -> scalar, optional
`estimator`:映射向量 -> 标量, optional
> Statistical function to estimate within each categorical bin.
> 统计函数用于估计每个分类纸条中的值。.
`ci`:float or “sd” or None, optional
> Size of confidence intervals to draw around estimated values. If “sd”, skip bootstrapping and draw the standard deviation of the observations. If `None`, no bootstrapping will be performed, and error bars will not be drawn.
> Number of bootstrap iterations to use when computing confidence intervals.
> 计算置信区间需要的Boostrap迭代次数。
`units`:name of variable in `data` or vector data, optional
> Identifier of sampling units, which will be used to perform a multilevel bootstrap and account for repeated measures design.
> 采样单元的标识符,用于执行多级bootstrap并解释重复测量设计。
`orient`:“v” | “h”, optional
> Orientation of the plot (vertical or horizontal). This is usually inferred from the dtype of the input variables, but can be used to specify when the “categorical” variable is a numeric or when plotting wide-form data.
> Color for all of the elements, or seed for a gradient palette.
> 作用于所有元素的颜色,或者渐变色的种子。
`palette`:palette name, list, or dict, optional
> Colors to use for the different levels of the `hue` variable. Should be something that can be interpreted by [`color_palette()`](seaborn.color_palette.html#seaborn.color_palette "seaborn.color_palette"), or a dictionary mapping hue levels to matplotlib colors.
> Proportion of the original saturation to draw colors at. Large patches often look better with slightly desaturated colors, but set this to `1` if you want the plot colors to perfectly match the input color spec.
> Proportion of the original saturation to draw colors at. Large patches often look better with slightly desaturated colors, but set this to `1` if you want the plot colors to perfectly match the input color spec.
`errcolor`:matplotlib color
> Color for the lines that represent the confidence interval.
> 表示置信区间的线的颜色。
`errwidth`:float, optional
> Thickness of error bar lines (and caps).
> 误差条的线的厚度。
`capsize`:float, optional
> Width of the “caps” on error bars.
> 误差条端部的宽度。
`dodge`:bool, optional
**dodge** : 布尔型, optional
> When hue nesting is used, whether elements should be shifted along the categorical axis.
`ax`:matplotlib Axes, optional
> Axes object to draw the plot onto, otherwise uses the current Axes.
> 指定一个Axes用于绘图,如果不指定,则使用当前的Axes。
`kwargs`:key, value mappings
> Other keyword arguments are passed through to `plt.bar` at draw time.
> 其他的关键词参数在绘图时通过 `plt.bar` 传入。
返回值:`ax`:matplotlib Axes
> Returns the Axes object with the plot drawn onto it.
> 返回有图表绘制的Axes对象。
See also
Show the counts of observations in each categorical bin.Show point estimates and confidence intervals using scatterplot glyphs.Combine a categorical plot with a class:<cite>FacetGrid</cite>.
Use [`catplot()`](seaborn.catplot.html#seaborn.catplot"seaborn.catplot") to combine a [`barplot()`](#seaborn.barplot"seaborn.barplot") and a [`FacetGrid`](seaborn.FacetGrid.html#seaborn.FacetGrid"seaborn.FacetGrid"). This allows grouping within additional categorical variables. Using [`catplot()`](seaborn.catplot.html#seaborn.catplot"seaborn.catplot") is safer than using [`FacetGrid`](seaborn.FacetGrid.html#seaborn.FacetGrid"seaborn.FacetGrid") directly, as it ensures synchronization of variable order across facets:
Plot data and regression model fits across a FacetGrid.
在FacetGrid对象上绘制数据和回归模型。
This function combines [`regplot()`](seaborn.regplot.html#seaborn.regplot"seaborn.regplot") and [`FacetGrid`](seaborn.FacetGrid.html#seaborn.FacetGrid"seaborn.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](../tutorial/regression.html#regression-tutorial) for more information.
The parameters to this function span most of the options in [`FacetGrid`](seaborn.FacetGrid.html#seaborn.FacetGrid"seaborn.FacetGrid"), although there may be occasional cases where you will want to use that class and [`regplot()`](seaborn.regplot.html#seaborn.regplot"seaborn.regplot") directly.
> Variables that define subsets of the data, which will be drawn on separate facets in the grid. See the `*_order` parameters to control the order of levels of this variable.
> Colors to use for the different levels of the `hue` variable. Should be something that can be interpreted by [`color_palette()`](seaborn.color_palette.html#seaborn.color_palette "seaborn.color_palette"), or a dictionary mapping hue levels to matplotlib colors.
`markers`:matplotlib marker code or list of marker codes, optional
`markers`:matplotlib标记代码或标记代码列表,可选
> Markers for the scatterplot. If a list, each marker in the list will be used for each level of the `hue` variable.
> 散点图的标记。如果是列表,列表中的每个标记将用于`hue`变量的每个级别。
`share{x,y}`:bool, ‘col’, or ‘row’ optional
`share{x,y}`:布尔值,‘col’,或 ‘row’ ,可选
> If true, the facets will share y axes across columns and/or x axes across rows.
> 如果为true,则分面(facet)之间将跨列共享y轴和/或跨行共享x轴。
`{hue,col,row}_order`:lists, optional
`{hue,col,row}_order`:列表,可选
> Order for the levels of the faceting variables. By default, this will be the order that the levels appear in `data` or, if the variables are pandas categoricals, the category order.
> If `True` and there is a `hue` variable, add a legend.
> 如果为“True”并且有一个`hue`变量,则添加一个图例。
`legend_out`:bool, optional
`legend_out`:布尔值,可选
> If `True`, the figure size will be extended, and the legend will be drawn outside the plot on the center right.
> 如果为“True”,图形尺寸将被扩展,图例将被绘制在图像中部右侧之外。
`x_estimator`:callable that maps vector -> scalar, optional
`x_estimator`:可调用的映射向量->标量,可选
> Apply this function to each unique value of `x` and plot the resulting estimate. This is useful when `x` is a discrete variable. If `x_ci` is given, this estimate will be bootstrapped and a confidence interval will be drawn.
> Bin the `x` variable 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_estimator` is `numpy.mean`.
`x_ci`:“ci”, “sd”, int in [0, 100] or None, optional
`x_ci`:“ci”。“sd”, 在[0,100]间的整数或None,可选
> Size of the confidence interval used when plotting a central tendency for discrete values of `x`. If `"ci"`, defer to the value of the `ci` parameter. If `"sd"`, skip bootstrapping and show the standard deviation of the observations in each bin.
> If `True`, draw a scatterplot with the underlying observations (or the `x_estimator` values).
> 如果为 `True`,则绘制带有基础观测值(或`x_estimator` 值)的散点图。
`fit_reg`:bool, optional
`fit_reg`:布尔值,可选
> If `True`, estimate and plot a regression model relating the `x` and `y` variables.
> 如果为 `True`,则估计并绘制与 `x` 和 `y` 变量相关的回归模型。
`ci`:int in [0, 100] or None, optional
`ci`:在[0,100]间的整数或None,可选
> 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.
> 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.
> If the `x` and `y` observations 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.
> If `order` is greater than 1, use `numpy.polyfit` to estimate a polynomial regression.
> 如果`order`大于1,使用`numpy.polyfit`来估计多项式回归。
`logistic`:bool, optional
`logistic`:布尔值,可选
> If `True`, assume that `y` is a binary variable and use `statsmodels` to 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 `ci` to None.
> If `True`, use `statsmodels` to estimate a nonparametric lowess model (locally weighted linear regression). Note that confidence intervals cannot currently be drawn for this kind of model.
> If `True`, use `statsmodels` to 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 `ci` to None.
> 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 `x` must be positive for this to work.
> Confounding variables to regress out of the `x` or `y` variables before plotting.
> 混淆(Confounding)变量以在绘图之前退回`x`或`y`变量。
`truncate`:bool, optional
`truncate`:布尔值,可选
> By default, the regression line is drawn to fill the x axis limits after the scatterplot is drawn. If `truncate` is `True`, it will instead by bounded by the data limits.
> Add uniform random noise of this size to either the `x` or `y` variables. 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.
> Additional keyword arguments to pass to `plt.scatter` and `plt.plot`.
> 传递给`plt.scatter`和`plt.plot`的附加关键字参数。
See also
也可以查看
Plot data and a conditional model fit.Subplot grid for plotting conditional relationships.Combine [`regplot()`](seaborn.regplot.html#seaborn.regplot"seaborn.regplot") and [`PairGrid`](seaborn.PairGrid.html#seaborn.PairGrid"seaborn.PairGrid")(when used with `kind="reg"`).
The [`regplot()`](seaborn.regplot.html#seaborn.regplot"seaborn.regplot") and [`lmplot()`](#seaborn.lmplot"seaborn.lmplot") functions are closely related, but the former is an axes-level function while the latter is a figure-level function that combines [`regplot()`](seaborn.regplot.html#seaborn.regplot"seaborn.regplot") and [`FacetGrid`](seaborn.FacetGrid.html#seaborn.FacetGrid"seaborn.FacetGrid").
These examples focus on basic regression model plots to exhibit the various faceting options; see the [`regplot()`](seaborn.regplot.html#seaborn.regplot"seaborn.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`](seaborn.FacetGrid.html#seaborn.FacetGrid"seaborn.FacetGrid") docs.
There are a number of mutually exclusive options for estimating the regression model. See the [tutorial](../tutorial/regression.html#regression-tutorial) for more information.
> Input variables. If strings, these should correspond with column names in `data`. When pandas objects are used, axes will be labeled with the series name.
`x_estimator`:callable that maps vector -> scalar, optional
`x_estimator`:可调用的映射向量 ->标量,可选
> Apply this function to each unique value of `x` and plot the resulting estimate. This is useful when `x` is a discrete variable. If `x_ci` is given, this estimate will be bootstrapped and a confidence interval will be drawn.
> Bin the `x` variable 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_estimator` is `numpy.mean`.
`x_ci`:“ci”, “sd”, int in [0, 100] or None, optional
`x_ci`:"ci",'sd',位于 [0, 100]之间的整数或None,可选
> Size of the confidence interval used when plotting a central tendency for discrete values of `x`. If `"ci"`, defer to the value of the `ci` parameter. If `"sd"`, skip bootstrapping and show the standard deviation of the observations in each bin.
> If `True`, draw a scatterplot with the underlying observations (or the `x_estimator` values).
> 如果为 `True`,则绘制带有基础观测值(或`x_estimator` 值)的散点图。
`fit_reg`:bool, optional
`fit_reg`:布尔值,可选
> If `True`, estimate and plot a regression model relating the `x` and `y` variables.
> 如果为 `True`,则估计并绘制与 `x` 和 `y` 变量相关的回归模型。
`ci`:int in [0, 100] or None, optional
`ci`:位于 [0, 100]之间的整数或None,可选
> 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.
> 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.
> If the `x` and `y` observations 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.
> If `order` is greater than 1, use `numpy.polyfit` to estimate a polynomial regression.
> 如果`order`大于1,使用`numpy.polyfit`来估计多项式回归。
`logistic`:bool, optional
`logistic`:布尔值,可选
> If `True`, assume that `y` is a binary variable and use `statsmodels` to 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 `ci` to None.
> If `True`, use `statsmodels` to estimate a nonparametric lowess model (locally weighted linear regression). Note that confidence intervals cannot currently be drawn for this kind of model.
> If `True`, use `statsmodels` to 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 `ci` to None.
> 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 `x` must be positive for this to work.
> Confounding variables to regress out of the `x` or `y` variables before plotting.
> 混淆(Confounding)变量以在绘图之前退回`x`或`y`变量。
`truncate`:bool, optional
`truncate`:布尔值,可选
> By default, the regression line is drawn to fill the x axis limits after the scatterplot is drawn. If `truncate` is `True`, it will instead by bounded by the data limits.
> Add uniform random noise of this size to either the `x` or `y` variables. 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.
> Additional keyword arguments to pass to `plt.scatter` and `plt.plot`.
> 传递给`plt.scatter`和`plt.plot`的附加关键字参数。
`ax`:matplotlib Axes, optional
`ax`:matplotlib Axes对象,可选
> Axes object to draw the plot onto, otherwise uses the current Axes.
> 绘制到指定轴对象,否则在当前轴对象上绘图。
返回值:`ax`:matplotlib Axes
返回值:`ax`:matplotlib Axes对象
> The Axes object containing the plot.
> 包含了图像的Axes对象。
See also
也可以看看
Combine [`regplot()`](#seaborn.regplot"seaborn.regplot") and [`FacetGrid`](seaborn.FacetGrid.html#seaborn.FacetGrid"seaborn.FacetGrid") to plot multiple linear relationships in a dataset.Combine [`regplot()`](#seaborn.regplot"seaborn.regplot") and [`JointGrid`](seaborn.JointGrid.html#seaborn.JointGrid"seaborn.JointGrid")(when used with `kind="reg"`).Combine [`regplot()`](#seaborn.regplot"seaborn.regplot") and [`PairGrid`](seaborn.PairGrid.html#seaborn.PairGrid"seaborn.PairGrid")(when used with `kind="reg"`).Plot the residuals of a linear regression model.
The [`regplot()`](#seaborn.regplot"seaborn.regplot") and [`lmplot()`](seaborn.lmplot.html#seaborn.lmplot"seaborn.lmplot") functions are closely related, but the former is an axes-level function while the latter is a figure-level function that combines [`regplot()`](#seaborn.regplot"seaborn.regplot") and [`FacetGrid`](seaborn.FacetGrid.html#seaborn.FacetGrid"seaborn.FacetGrid").
It’s also easy to combine combine [`regplot()`](#seaborn.regplot"seaborn.regplot") and [`JointGrid`](seaborn.JointGrid.html#seaborn.JointGrid"seaborn.JointGrid") or [`PairGrid`](seaborn.PairGrid.html#seaborn.PairGrid"seaborn.PairGrid") through the [`jointplot()`](seaborn.jointplot.html#seaborn.jointplot"seaborn.jointplot") and [`pairplot()`](seaborn.pairplot.html#seaborn.pairplot"seaborn.pairplot") functions, although these do not directly accept all of [`regplot()`](#seaborn.regplot"seaborn.regplot")’s parameters.
This function will regress y on x (possibly as a robust or polynomial regression) and then draw a scatterplot of the residuals. You can optionally fit a lowess smoother to the residual plot, which can help in determining if there is structure to the residuals.
`data`:DataFrame, 可选
参数:`x`:vector or string
> 如果 *x* 和 *y* 是列名,则指定使用的DataFrame
> Data or column name in <cite>data</cite> for the predictor variable.
`lowess`: 布尔值, 可选
`y`:vector or string
> 将局部加权回归散点平滑法(LOWESS)应用到残差散点图中。
> Data or column name in <cite>data</cite> for the response variable.
> DataFrame to use if <cite>x</cite> and <cite>y</cite> are column names.
`order`:整数,可选
`lowess`:boolean, optional
> 计算残差时拟合多项式的阶数。
> Fit a lowess smoother to the residual scatterplot.
`robust`:布尔值,可选
`{x, y}_partial`:matrix or string(s) , optional
> 在计算残差时拟合稳健的线性回归。
> Matrix with same first dimension as <cite>x</cite>, or column name(s) in <cite>data</cite>. These variables are treated as confounding and are removed from the <cite>x</cite> or <cite>y</cite> variables before plotting.
`dropna`:布尔值,可选
`order`:int, optional
> 如果为True,则在拟合和绘图时忽略缺少的数据。
> Order of the polynomial to fit when calculating the residuals.
`label`:字符串,可选
`robust`:boolean, optional
> 将在任何图的图例中使用的标签。
> Fit a robust linear regression when calculating the residuals.
`color`:matplotlib 颜色,可选
`dropna`:boolean, optional
> 用于绘图的所有元素的颜色。
> If True, ignore observations with missing data when fitting and plotting.
`{scatter, line}_kws`: 字典,可选
`label`:string, optional
> 用于绘制图像的组件而传递给 scatter() 和 plot() 的其他关键字参数。
> Label that will be used in any plot legends.
`ax`:matplotlib轴,可选
`color`:matplotlib color, optional
> 绘制到指定轴对象,否则在当前轴对象上绘图,如果轴不存在则创建一个新轴。
> Color to use for all elements of the plot.
`{scatter, line}_kws`:dictionaries, optional
返回值:ax:matplotlib Axes对象
> Additional keyword arguments passed to scatter() and plot() for drawing the components of the plot.
> 带有回归图像的轴对象
`ax`:matplotlib axis, optional
> Plot into this axis, otherwise grab the current axis or make a new one if not existing.
Apply a plotting function to each facet’s subset of the data.
将绘图函数应用于每个方面的数据子集。
参数:`func`:callable
参数:`func`:可调用
> A plotting function that takes data and keyword arguments. It must plot to the currently active matplotlib Axes and take a <cite>color</cite> keyword argument. If faceting on the <cite>hue</cite> dimension, it must also take a <cite>label</cite> keyword argument.
> Column names in self.data that identify variables with data to plot. The data for each variable is passed to <cite>func</cite> in the order the variables are specified in the call.
Like `.map` but passes args as strings and inserts data in kwargs.
和 `.map`类似,但是将args作为字符串传递并将数据插入到kwargs中.
This method is suitable for plotting with functions that accept a long-form DataFrame as a <cite>data</cite> keyword argument and access the data in that DataFrame using string variable names.
> A plotting function that takes data and keyword arguments. Unlike the <cite>map</cite> method, a function used here must “understand” Pandas objects. It also must plot to the currently active matplotlib Axes and take a <cite>color</cite> keyword argument. If faceting on the <cite>hue</cite> dimension, it must also take a <cite>label</cite> keyword argument.
> Column names in self.data that identify variables with data to plot. The data for each variable is passed to <cite>func</cite> in the order the variables are specified in the call.
Subplot grid for plotting pairwise relationships in a dataset.
用于绘制数据集中成对关系的子图网格。
This class maps each variable in a dataset onto a column and row in a grid of multiple axes. Different axes-level plotting functions can be used to draw bivariate plots in the upper and lower triangles, and the the marginal distribution of each variable can be shown on the diagonal.
It can also represent an additional level of conditionalization with the `hue` parameter, which plots different subets of data in different colors. This uses color to resolve elements on a third dimension, but only draws subsets on top of each other and will not tailor the `hue` parameter for the specific visualization the way that axes-level functions that accept `hue` will.
> Tidy (long-form) dataframe where each column is a variable and each row is an observation.
> 整洁(长形式)数据框,其中每列是一个变量,每行是一个观察。
`hue`:string (variable name), optional
`hue`:字符串 (变量名), 可选
> Variable in `data` to map plot aspects to different colors.
> `data`中的变量,将绘图的不同面映射为不同的颜色。
`hue_order`:list of strings
`hue_order`:字符串列表
> Order for the levels of the hue variable in the palette
> 调色板中色调变量的等级顺序
`palette`:dict or seaborn color palette
`palette`:字典或者seaborn调色板
> Set of colors for mapping the `hue` variable. If a dict, keys should be values in the `hue` variable.
> 用于映射`hue`变量的颜色集.如果是一个字典,键应为`hue`变量中的值。
`hue_kws`:dictionary of param -> list of values mapping
`hue_kws`:参数字典 -> 值列表映射
> Other keyword arguments to insert into the plotting call to let other plot attributes vary across levels of the hue variable (e.g. the markers in a scatterplot).
| [`__init__`](#seaborn.PairGrid.__init__"seaborn.PairGrid.__init__")(data[, hue, hue_order, palette, …]) | Initialize the plot figure and PairGrid object. |
| `add_legend`([legend_data, title, label_order]) | Draw a legend, maybe placing it outside axes and resizing the figure. |
| [`map`](seaborn.PairGrid.map.html#seaborn.PairGrid.map"seaborn.PairGrid.map")(func, **kwargs) | Plot with the same function in every subplot. |
| [`map_diag`](seaborn.PairGrid.map_diag.html#seaborn.PairGrid.map_diag"seaborn.PairGrid.map_diag")(func, **kwargs) | Plot with a univariate function on each diagonal subplot. |
| [`map_lower`](seaborn.PairGrid.map_lower.html#seaborn.PairGrid.map_lower"seaborn.PairGrid.map_lower")(func, **kwargs) | Plot with a bivariate function on the lower diagonal subplots. |
| [`map_offdiag`](seaborn.PairGrid.map_offdiag.html#seaborn.PairGrid.map_offdiag"seaborn.PairGrid.map_offdiag")(func, **kwargs) | Plot with a bivariate function on the off-diagonal subplots. |
| [`map_upper`](seaborn.PairGrid.map_upper.html#seaborn.PairGrid.map_upper"seaborn.PairGrid.map_upper")(func, **kwargs) | Plot with a bivariate function on the upper diagonal subplots. |
| `savefig`(*args, **kwargs) | Save the figure. |
| `set`(**kwargs) | Set attributes on each subplot Axes. |
> Must take x, y arrays as positional arguments and draw onto the “currently active” matplotlib Axes. Also needs to accept kwargs called `color` and `label`.
Plot with a univariate function on each diagonal subplot.
在每一个对角线子图上用一个单变量函数绘制。
参数:`func`:callable plotting function
参数:`func`:可调用的绘图函数
> Must take an x array as a positional argument and draw onto the “currently active” matplotlib Axes. Also needs to accept kwargs called `color` and `label`.
Plot with a bivariate function on the off-diagonal subplots.
在非对角线子图上用一个双变量函数绘图。
参数:`func`:callable plotting function
参数:`func`:可调用的绘图函数
> Must take x, y arrays as positional arguments and draw onto the “currently active” matplotlib Axes. Also needs to accept kwargs called `color` and `label`.
Plot with a bivariate function on the lower diagonal subplots.
在下对角线子图上用一个双变量函数绘图。
参数:`func`:callable plotting function
参数:`func`:可调用的绘图函数
> Must take x, y arrays as positional arguments and draw onto the “currently active” matplotlib Axes. Also needs to accept kwargs called `color` and `label`.
Plot with a bivariate function on the upper diagonal subplots.
在上对角线子图上用一个双变量函数绘图。
参数:`func`:callable plotting function
参数:`func`:可调用的绘图函数
> Must take x, y arrays as positional arguments and draw onto the “currently active” matplotlib Axes. Also needs to accept kwargs called `color` and `label`.
| [`__init__`](#seaborn.JointGrid.__init__"seaborn.JointGrid.__init__")(x, y[, data, height, ratio, space, …]) | Set up the grid of subplots. |
| `annotate`(func[, template, stat, loc]) | Annotate the plot with a statistic about the relationship. |
| [`plot`](seaborn.JointGrid.plot.html#seaborn.JointGrid.plot"seaborn.JointGrid.plot")(joint_func, marginal_func[, annot_func]) | Shortcut to draw the full plot. |
| [`plot_joint`](seaborn.JointGrid.plot_joint.html#seaborn.JointGrid.plot_joint"seaborn.JointGrid.plot_joint")(func, **kwargs) | Draw a bivariate plot of <cite>x</cite> and <cite>y</cite>. |
| [`plot_marginals`](seaborn.JointGrid.plot_marginals.html#seaborn.JointGrid.plot_marginals"seaborn.JointGrid.plot_marginals")(func, **kwargs) | Draw univariate plots for <cite>x</cite> and <cite>y</cite> separately. |
> This must take a 1d array of data as the first positional argument, it must plot on the “current” axes, and it must accept a “vertical” keyword argument to orient the measure dimension of the plot vertically.
> A dictionary of parameters or the name of a preconfigured set.
> 一个参数字典或者一个预配置集的名称。
`rc`:dict, optional
rc:字典,可选的
> Parameter mappings to override the values in the preset seaborn style dictionaries. This only updates parameters that are considered part of the style definition.
> A dictionary of parameters or the name of a preconfigured set.
> 一个参数字典或者一个预配置集的名称。
`rc`:dict, optional
rc:字典,可选
> Parameter mappings to override the values in the preset seaborn style dictionaries. This only updates parameters that are considered part of the style definition.
return a dict of parameters or use in a `with` statement to temporarily set the style.set parameters to scale plot elementsset the default color palette for figures
Return a parameter dict to scale elements of the figure.
This affects things like the size of the labels, lines, and other elements of the plot, but not the overall style. The base context is “notebook”, and the other contexts are “paper”, “talk”, and “poster”, which are version of the notebook parameters scaled by .8, 1.3, and 1.6, respectively.
This function returns an object that can be used in a `with` statement to temporarily change the context parameters.
参数:`context`:dict, None, or one of {paper, notebook, talk, poster}
> Separate scaling factor to independently scale the size of the font elements.
> 参数集或者是预设集合的名字
`rc`:dict, optional
`font_scale`:浮点数,可选
> Parameter mappings to override the values in the preset seaborn context dictionaries. This only updates parameters that are considered part of the context definition.
> 单独的缩放因子可以独立缩放字体元素大小
`rc`:dict,可选
> 参数映射以覆盖预设的seaborn的文本字典中的值。这只更新被视为文本定义的一部分的参数。
See also
也可参见
set the matplotlib parameters to scale plot elementsreturn a dict of parameters defining a figure styledefine the color palette for a plot
This affects things like the size of the labels, lines, and other elements of the plot, but not the overall style. The base context is “notebook”, and the other contexts are “paper”, “talk”, and “poster”, which are version of the notebook parameters scaled by .8, 1.3, and 1.6, respectively.
参数:`context`:dict, None, or one of {paper, notebook, talk, poster}
> A dictionary of parameters or the name of a preconfigured set.
`font_scale`:float, optional
> Separate scaling factor to independently scale the size of the font elements.
`rc`:dict, optional
> Parameter mappings to override the values in the preset seaborn context dictionaries. This only updates parameters that are considered part of the context definition.
See also
return a dictionary of rc parameters, or use in a `with` statement to temporarily set the context.set the default parameters for figure styleset the default color palette for figures
> Named seaborn palette to use as the source of colors.
See also
Color codes can be set through the high-level seaborn style manager.Color codes can also be set through the function that sets the matplotlib color cycle.
Examples
Map matplotlib color codes to the default seaborn palette.
Drawing attractive figures is important. When making figures for yourself, as you explore a dataset, it’s nice to have plots that are pleasant to look at. Visualizations are also central to communicating quantitative insights to an audience, and in that setting it’s even more necessary to have figures that catch the attention and draw a viewer in.
> 译者:[P3n9W31](https://github.com/P3n9W31)
Matplotlib is highly customizable, but it can be hard to know what settings to tweak to achieve an attractive plot. Seaborn comes with a number of customized themes and a high-level interface for controlling the look of matplotlib figures.
(Note that in versions of seaborn prior to 0.8, [`set()`](../generated/seaborn.set.html#seaborn.set"seaborn.set") was called on import. On later versions, it must be explicitly invoked).
Seaborn splits matplotlib parameters into two independent groups. The first group sets the aesthetic style of the plot, and the second scales various elements of the figure so that it can be easily incorporated into different contexts.
The interface for manipulating these parameters are two pairs of functions. To control the style, use the [`axes_style()`](../generated/seaborn.axes_style.html#seaborn.axes_style"seaborn.axes_style") and [`set_style()`](../generated/seaborn.set_style.html#seaborn.set_style"seaborn.set_style") functions. To scale the plot, use the [`plotting_context()`](../generated/seaborn.plotting_context.html#seaborn.plotting_context"seaborn.plotting_context") and [`set_context()`](../generated/seaborn.set_context.html#seaborn.set_context"seaborn.set_context") functions. In both cases, the first function returns a dictionary of parameters and the second sets the matplotlib defaults.
There are five preset seaborn themes: `darkgrid`, `whitegrid`, `dark`, `white`, and `ticks`. They are each suited to different applications and personal preferences. The default theme is `darkgrid`. As mentioned above, the grid helps the plot serve as a lookup table for quantitative information, and the white-on grey helps to keep the grid from competing with lines that represent data. The `whitegrid` theme is similar, but it is better suited to plots with heavy data elements:
For many plots, (especially for settings like talks, where you primarily want to use figures to provide impressions of patterns in the data), the grid is less necessary.
Both the `white` and `ticks` styles can benefit from removing the top and right axes spines, which are not needed. The seaborn function [`despine()`](../generated/seaborn.despine.html#seaborn.despine"seaborn.despine") can be called to remove them:
Some plots benefit from offsetting the spines away from the data, which can also be done when calling [`despine()`](../generated/seaborn.despine.html#seaborn.despine"seaborn.despine"). When the ticks don’t cover the whole range of the axis, the `trim` parameter will limit the range of the surviving spines.
You can also control which spines are removed with additional arguments to [`despine()`](../generated/seaborn.despine.html#seaborn.despine"seaborn.despine"):
Although it’s easy to switch back and forth, you can also use the [`axes_style()`](../generated/seaborn.axes_style.html#seaborn.axes_style"seaborn.axes_style") function in a `with` statement to temporarily set plot parameters. This also allows you to make figures with differently-styled axes:
If you want to customize the seaborn styles, you can pass a dictionary of parameters to the `rc` argument of [`axes_style()`](../generated/seaborn.axes_style.html#seaborn.axes_style"seaborn.axes_style") and [`set_style()`](../generated/seaborn.set_style.html#seaborn.set_style"seaborn.set_style"). Note that you can only override the parameters that are part of the style definition through this method. (However, the higher-level [`set()`](../generated/seaborn.set.html#seaborn.set"seaborn.set") function takes a dictionary of any matplotlib parameters).
A separate set of parameters control the scale of plot elements, which should let you use the same code to make plots that are suited for use in settings where larger or smaller plots are appropriate.
一组独立的参数控制绘图元素的比例,这允许您使用相同的代码来制作在适合使用不同大小图片场景下的图片。
First let’s reset the default parameters by calling [`set()`](../generated/seaborn.set.html#seaborn.set"seaborn.set"):
The four preset contexts, in order of relative size, are `paper`, `notebook`, `talk`, and `poster`. The `notebook` style is the default, and was used in the plots above.
Most of what you now know about the style functions should transfer to the context functions.
您现在知道的关于样式函数的大部分内容应该转移到环境函数中。
You can call [`set_context()`](../generated/seaborn.set_context.html#seaborn.set_context"seaborn.set_context") with one of these names to set the parameters, and you can override the parameters by providing a dictionary of parameter values.
You can also independently scale the size of the font elements when changing the context. (This option is also available through the top-level [`set()`](../generated/seaborn.set.html#seaborn.set"seaborn.set") function).
Both the style and the context can be quickly configured with the [`set()`](../generated/seaborn.set.html#seaborn.set"seaborn.set") function. This function also sets the default color palette, but that will be covered in more detail in the [next section](color_palettes.html#palette-tutorial) of the tutorial.