提交 a55079eb 编写于 作者: S Stuming
......@@ -5,10 +5,15 @@
> 欢迎任何人参与和完善:一个人可以走的很快,但是一群人却可以走的更远。
* [在线阅读](https://apachecn.github.io/seaborn-doc-zh)
* [贡献指南](CONTRIBUTING.md)
* [ApacheCN 机器学习交流群 629470233](http://shang.qq.com/wpa/qunwpa?idkey=30e5f1123a79867570f665aa3a483ca404b1c3f77737bc01ec520ed5f078ddef)
* [ApacheCN 学习资源](http://www.apachecn.org/)
## 贡献指南
项目当前处于翻译阶段,请查看[贡献指南](CONTRIBUTING.md),并在[整体进度](https://github.com/apachecn/seaborn-doc-zh/issues/1)中领取任务。
> 请您勇敢地去翻译和改进翻译。虽然我们追求卓越,但我们并不要求您做到十全十美,因此请不要担心因为翻译上犯错——在大部分情况下,我们的服务器已经记录所有的翻译,因此您不必担心会因为您的失误遭到无法挽回的破坏。(改编自维基百科)
## 联系方式
### 负责人
......
# seaborn.catplot
> 译者:[LIJIANcoder97](https://github.com/LIJIANcoder97)
```py
seaborn.catplot(x=None, y=None, hue=None, data=None, row=None, col=None, col_wrap=None, estimator=<function mean>, ci=95, n_boot=1000, units=None, order=None, hue_order=None, row_order=None, col_order=None, kind='strip', height=5, aspect=1, orient=None, color=None, palette=None, legend=True, legend_out=True, sharex=True, sharey=True, margin_titles=False, facet_kws=None, **kwargs)
```
......
# seaborn.stripplot
> 译者:[LIJIANcoder97](https://github.com/LIJIANcoder97)
```py
seaborn.stripplot(x=None, y=None, hue=None, data=None, order=None, hue_order=None, jitter=True, dodge=False, orient=None, color=None, palette=None, size=5, edgecolor='gray', linewidth=0, ax=None, **kwargs)
```
......
......@@ -4,85 +4,84 @@
seaborn.swarmplot(x=None, y=None, hue=None, data=None, order=None, hue_order=None, dodge=False, orient=None, color=None, palette=None, size=5, edgecolor='gray', linewidth=0, ax=None, **kwargs)
```
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”.
此功能类似于 [`stripplot()`](seaborn.stripplot.html#seaborn.stripplot "seaborn.stripplot"),,但调整点(仅沿分类轴),以便它们不重叠。 这样可以更好地表示值的分布,但不能很好地扩展到大量观察值。这种情节有时被称为“诅咒”
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.
* An array or list of vectors.
在大多数情况下,可以使用numpy或Python对象,但最好使用pandas对象,因为关联的名称将用于注释轴。此外,您可以使用分类类型来分组变量来控制绘图元素的顺序。
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.
此函数始终将其中一个变量视为分类,并在相关轴上的序数位置(0,1,... n)处绘制数据,即使数据具有数字或日期类型也是如此
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.
有关更多信息,请参阅[教程](../tutorial/categorical.html#categorical-tutorial)
See the [tutorial](../tutorial/categorical.html#categorical-tutorial) for more information.
参数:`x, y, hue``数据`或矢量数据中的变量名称,可选
参数:`x, y, hue`:names of variables in `data` or vector data, optional
> 用于绘制长格式数据的输入。查看解释示例。
> Inputs for plotting long-form data. See examples for interpretation.
`data`:DataFrame, array, or 或数组列表, 可选
`data`:DataFrame, array, or list of arrays, optional
> 用于绘图的数据集。 如果 `x` 和 `y` 是不存在的, 会被解释成 wide-form. 否则会被解释成 long-form.
> Dataset for plotting. If `x` and `y` are absent, this is interpreted as wide-form. Otherwise it is expected to be long-form.
`order, hue_order`:字符串列表,可选
`order, hue_order`:lists of strings, optional
> 命令绘制分类级别,否则从数据对象推断级别。
> Order to plot the categorical levels in, otherwise the levels are inferred from the data objects.
`dodge`:布尔,可选
`dodge`:bool, optional
> 使用`hue`嵌套时,将其设置为`True`将沿着分类轴分离不同色调级别的条带。 否则,每个级别的点将绘制在一个群中。
> 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.
`orient`:“v” &#124; “h”, 可选
`orient`:“v” &#124; “h”, optional
> 图的方向(垂直或水平)。这通常是从输入变量的dtype推断出来的,但可用于指定“分类”变量何时是数字或何时绘制宽格式数据。
> 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.
`palette`:调色板名称, list, or dict, 可选
`palette`:palette name, list, or dict, optional
> 用于`hue`变量的不同级别的颜色。应该是[`color_palette()`](seaborn.color_palette.html#seaborn.color_palette "seaborn.color_palette"),可以解释的东西,或者是将色调级别映射到matplotlib颜色的字典。
> 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.
`size`:float, 可选
`size`:float, optional
> 标记的直径,以点为单位。 (尽管`plt.scatter`用于绘制点,但此处的`size`参数采用“普通”标记大小而不是大小^ 2,如`plt.scatter`。
> 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>.
带有类似API的传统盒须图。框图和核密度估计的组合。散点图,其中一个变量是分类的。可以与其他图一起使用以显示每个观察结果。使用类组合分类图:<cite>FacetGrid</cite>
Examples
Draw a single horizontal swarm plot:
绘制单个水平群图:
```py
>>> import seaborn as sns
......@@ -94,7 +93,7 @@ Draw a single horizontal swarm plot:
![http://seaborn.pydata.org/_images/seaborn-swarmplot-1.png](img/900c725fafc0f5e475a98f52f4ed7d04.jpg)
Group the swarms by a categorical variable:
通过分类变量对群组进行分组:
```py
>>> ax = sns.swarmplot(x="day", y="total_bill", data=tips)
......@@ -103,7 +102,7 @@ Group the swarms by a categorical variable:
![http://seaborn.pydata.org/_images/seaborn-swarmplot-2.png](img/414037bdbfc9b79cf5f12a30645f7301.jpg)
Draw horizontal swarms:
绘制水平群:
```py
>>> ax = sns.swarmplot(x="total_bill", y="day", data=tips)
......@@ -112,7 +111,7 @@ Draw horizontal swarms:
![http://seaborn.pydata.org/_images/seaborn-swarmplot-3.png](img/b03c6dbcd2d2f71c2e5eafa99b46d96b.jpg)
Color the points using a second categorical variable:
使用第二个分类变量为点着色:
```py
>>> ax = sns.swarmplot(x="day", y="total_bill", hue="sex", data=tips)
......@@ -121,7 +120,7 @@ Color the points using a second categorical variable:
![http://seaborn.pydata.org/_images/seaborn-swarmplot-4.png](img/12d5e5950bf28b7027b28766bc41989f.jpg)
Split each level of the `hue` variable along the categorical axis:
沿着分类轴拆分 `hue` 变量的每个级别:
```py
>>> ax = sns.swarmplot(x="day", y="total_bill", hue="smoker",
......@@ -131,7 +130,7 @@ Split each level of the `hue` variable along the categorical axis:
![http://seaborn.pydata.org/_images/seaborn-swarmplot-5.png](img/6f9585fcbe42e72521292b80b0fdc97a.jpg)
Control swarm order by passing an explicit order:
通过传递显式顺序来控制swarm顺序:
```py
>>> ax = sns.swarmplot(x="time", y="tip", data=tips,
......@@ -141,7 +140,7 @@ Control swarm order by passing an explicit order:
![http://seaborn.pydata.org/_images/seaborn-swarmplot-6.png](img/73bbf8c6208a6e1c0dda89091dd509a4.jpg)
Plot using larger points:
绘制使用更大的点
```py
>>> ax = sns.swarmplot(x="time", y="tip", data=tips, size=6)
......@@ -150,7 +149,7 @@ Plot using larger points:
![http://seaborn.pydata.org/_images/seaborn-swarmplot-7.png](img/34aa97c61dd6f6176fa2256880526439.jpg)
Draw swarms of observations on top of a box plot:
在箱形图上绘制大量观察结果:
```py
>>> ax = sns.boxplot(x="tip", y="day", data=tips, whis=np.inf)
......@@ -160,7 +159,7 @@ Draw swarms of observations on top of a box plot:
![http://seaborn.pydata.org/_images/seaborn-swarmplot-8.png](img/d992e6312a3ed98025ad0913dbc46228.jpg)
Draw swarms of observations on top of a violin plot:
在小提琴图的顶部画出大量的观察结果:
```py
>>> ax = sns.violinplot(x="day", y="total_bill", data=tips, inner=None)
......@@ -171,7 +170,7 @@ Draw swarms of observations on top of a violin plot:
![http://seaborn.pydata.org/_images/seaborn-swarmplot-9.png](img/735aa7eaadb9afb7a47a2d079b28a10b.jpg)
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:
使用[`catplot()`](seaborn.catplot.html#seaborn.catplot "seaborn.catplot") 去组合 [`swarmplot()`](#seaborn.swarmplot "seaborn.swarmplot")[`FacetGrid`](seaborn.FacetGrid.html#seaborn.FacetGrid "seaborn.FacetGrid"). 这允许在其他分类变量中进行分组。 使用 [`catplot()`](seaborn.catplot.html#seaborn.catplot "seaborn.catplot") 比直接使用 [`FacetGrid`](seaborn.FacetGrid.html#seaborn.FacetGrid "seaborn.FacetGrid") 更安全,因为它确保了跨 facet 的变量顺序的同步
```py
>>> g = sns.catplot(x="sex", y="total_bill",
......@@ -181,4 +180,4 @@ Use [`catplot()`](seaborn.catplot.html#seaborn.catplot "seaborn.catplot") to com
```
![http://seaborn.pydata.org/_images/seaborn-swarmplot-10.png](img/7c1bc4a2871b9e0dbe2c23ed05fcae1b.jpg)
\ No newline at end of file
![http://seaborn.pydata.org/_images/seaborn-swarmplot-10.png](img/7c1bc4a2871b9e0dbe2c23ed05fcae1b.jpg)
# seaborn.boxplot
> 译者:[FindNorthStar](https://github.com/FindNorthStar)
```py
seaborn.boxplot(x=None, y=None, hue=None, data=None, order=None, hue_order=None, orient=None, color=None, palette=None, saturation=0.75, width=0.8, dodge=True, fliersize=5, linewidth=None, whis=1.5, notch=False, ax=None, **kwargs)
```
......
# seaborn.violinplot
> 译者:[FindNorthStar](https://github.com/FindNorthStar)
```py
seaborn.violinplot(x=None, y=None, hue=None, data=None, order=None, hue_order=None, bw='scott', cut=2, scale='area', scale_hue=True, gridsize=100, width=0.8, inner='box', split=False, dodge=True, orient=None, linewidth=None, color=None, palette=None, saturation=0.75, ax=None, **kwargs)
```
......
# seaborn.boxenplot
> 译者:[FindNorthStar](https://github.com/FindNorthStar)
```py
seaborn.boxenplot(x=None, y=None, hue=None, data=None, order=None, hue_order=None, orient=None, color=None, palette=None, saturation=0.75, width=0.8, dodge=True, k_depth='proportion', linewidth=None, scale='exponential', outlier_prop=None, ax=None, **kwargs)
```
Draw an enhanced box plot for larger datasets.
为更大的数据集绘制增强的箱型图。
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:
这种风格的绘图最初被命名为“信值图”,因为它显示了大量被定义为“置信区间”的分位数。它类似于绘制分布的非参数表示的箱形图,其中所有特征对应于实际观察的数值点。通过绘制更多分位数,它提供了有关分布形状的更多信息,特别是尾部数据的分布。欲了解更详细的解释,您可以阅读介绍该绘图的论文:
[https://vita.had.co.nz/papers/letter-value-plot.html](https://vita.had.co.nz/papers/letter-value-plot.html)
Input data can be passed in a variety of formats, including:
输入数据可以通过多种格式传入,包括:
* 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.
* An array or list of vectors.
* 格式为列表,numpy数组或pandas Series对象的数据向量可以直接传递给`x``y``hue`参数。
* 对于长格式的DataFrame,`x``y`,和`hue`参数会决定如何绘制数据。
* 对于宽格式的DataFrame,每一列数值列都会被绘制。
* 一个数组或向量的列表。
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.
在大多数情况下,可以使用numpy或Python对象,但更推荐使用pandas对象,因为与数据关联的列名/行名可以用于标注横轴/纵轴的名称。此外,您可以使用分类类型对变量进行分组以控制绘图元素的顺序。
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.
此函数始终将其中一个变量视为分类,并在相关轴上的序数位置(0,1,... n)处绘制数据,即使数据属于数值类型或日期类型也是如此。
See the [tutorial](../tutorial/categorical.html#categorical-tutorial) for more information.
更多信息请参阅 [教程](../tutorial/categorical.html#categorical-tutorial)
参数:`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” &#124; “h”, optional
`orient`:“v” &#124; “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.
> 控制绘图的方向(垂直或水平)。这通常是从输入变量的dtype推断出来的,但是当“分类”变量为数值型或绘制宽格式数据时可用于指定绘图的方向。
`color`:matplotlib color, optional
`color`:matplotlib颜色,可选
> 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.
> 用于`hue`变量的不同级别的颜色。可以从 [`color_palette()`](seaborn.color_palette.html#seaborn.color_palette "seaborn.color_palette") 得到一些解释,或者将色调级别映射到matplotlib颜色的字典。
`saturation`:float, optional
`saturation`:float,可选
> 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.
> 控制用于绘制颜色的原始饱和度的比例。通常大幅填充在轻微不饱和的颜色下看起来更好,如果您希望绘图颜色与输入颜色规格完美匹配可将其设置为`1`。
`width`:float, optional
`width`:float,可选
> Width of a full element when not using hue nesting, or width of all the elements for one level of the major grouping variable.
> 不使用色调嵌套时完整元素的宽度,或主要分组变量一个级别的所有元素的宽度。
`dodge`:bool, optional
`dodge`:bool,可选
> When hue nesting is used, whether elements should be shifted along the categorical axis.
> 使用色调嵌套时,元素是否应沿分类轴移动。
`k_depth`:“proportion” &#124; “tukey” &#124; “trustworthy”, optional
`k_depth`:“proportion” &#124; “tukey” &#124; “trustworthy”,可选
> 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.
> 通过增大百分比的粒度控制绘制的盒形图数目。所有方法都在Wickham的论文中有详细描述。每个参数代表利用不同的统计特性对异常值的数量做出不同的假设。
`linewidth`:float, optional
`linewidth`:float,可选
> Width of the gray lines that frame the plot elements.
> 构图元素的灰线宽度。
`scale`:“linear” &#124; “exponential” &#124; “area”
> 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.
> 用于控制增强箱型图宽度的方法。所有参数都会给显示效果造成影响。 “linear” 通过恒定的线性因子减小宽度,“exponential” 使用未覆盖的数据的比例调整宽度, “area” 与所覆盖的数据的百分比成比例。
`outlier_prop`:float, optional
`outlier_prop`:float,可选
> 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].
> 被认为是异常值的数据比例。与 `k_depth` 结合使用以确定要绘制的百分位数。默认值为0.007作为异常值的比例。该参数取值应在[0,1]范围内。
`ax`:matplotlib Axes, optional
`ax`:matplotlib轴,可选
> Axes object to draw the plot onto, otherwise uses the current Axes.
> 绘图时使用的Axes轴对象,否则使用当前Axes轴对象。
`kwargs`key, value mappings
`kwargs`键,值映射
> Other keyword arguments are passed through to `plt.plot` and `plt.scatter` at draw time.
> 其他在绘制时传递给`plt.plot`和`plt.scatter`参数。
返回值:`ax`:matplotlib Axes
返回值:`ax`:matplotlib
> Returns the Axes object with the plot drawn onto it.
> 返回Axes对轴象,并在其上绘制绘图。
See also
亦可参见
A combination of boxplot and kernel density estimation.A traditional box-and-whisker plot with a similar API.
boxplot和核密度估计的结合。一个传统的箱型图具有类似的API。
Examples
示例
Draw a single horizontal boxen plot:
绘制一个独立的横向增强箱型图:
```py
>>> import seaborn as sns
......@@ -108,7 +110,7 @@ Draw a single horizontal boxen plot:
![http://seaborn.pydata.org/_images/seaborn-boxenplot-1.png](img/ea7362d005109093ddfe7d7a0039a13e.jpg)
Draw a vertical boxen plot grouped by a categorical variable:
根据分类变量分组绘制一个纵向的增强箱型图:
```py
>>> ax = sns.boxenplot(x="day", y="total_bill", data=tips)
......@@ -117,7 +119,7 @@ Draw a vertical boxen plot grouped by a categorical variable:
![http://seaborn.pydata.org/_images/seaborn-boxenplot-2.png](img/31c79f0cf22d453e10799da960e3e801.jpg)
Draw a letter value plot with nested grouping by two categorical variables:
根据2个分类变量嵌套分组绘制一个增强箱型图:
```py
>>> ax = sns.boxenplot(x="day", y="total_bill", hue="smoker",
......@@ -127,7 +129,7 @@ Draw a letter value plot with nested grouping by two categorical variables:
![http://seaborn.pydata.org/_images/seaborn-boxenplot-3.png](img/1db91ed8446afc825fa5bba21f1ef278.jpg)
Draw a boxen plot with nested grouping when some bins are empty:
当一些数据为空时根据嵌套分组绘制一个增强箱型图:
```py
>>> ax = sns.boxenplot(x="day", y="total_bill", hue="time",
......@@ -137,7 +139,7 @@ Draw a boxen plot with nested grouping when some bins are empty:
![http://seaborn.pydata.org/_images/seaborn-boxenplot-4.png](img/2e57af8b26439c244046ff7846601335.jpg)
Control box order by passing an explicit order:
通过显式传入参数指定顺序控制箱型图的显示顺序:
```py
>>> ax = sns.boxenplot(x="time", y="tip", data=tips,
......@@ -147,7 +149,7 @@ Control box order by passing an explicit order:
![http://seaborn.pydata.org/_images/seaborn-boxenplot-5.png](img/e8fa81696195ce058546e429317075bc.jpg)
Draw a boxen plot for each numeric variable in a DataFrame:
针对DataFrame里每一个数值型变量绘制增强箱型图:
```py
>>> iris = sns.load_dataset("iris")
......@@ -157,7 +159,7 @@ Draw a boxen plot for each numeric variable in a DataFrame:
![http://seaborn.pydata.org/_images/seaborn-boxenplot-6.png](img/a9e939280daed8ec0712c8e6e6be78fb.jpg)
Use [`stripplot()`](seaborn.stripplot.html#seaborn.stripplot "seaborn.stripplot") to show the datapoints on top of the boxes:
使用 [`stripplot()`](seaborn.stripplot.html#seaborn.stripplot "seaborn.stripplot") 显示箱型图顶部的数据点:
```py
>>> ax = sns.boxenplot(x="day", y="total_bill", data=tips)
......@@ -168,7 +170,7 @@ Use [`stripplot()`](seaborn.stripplot.html#seaborn.stripplot "seaborn.stripplot"
![http://seaborn.pydata.org/_images/seaborn-boxenplot-7.png](img/fb3de8051b91bb0be2143717f96c0a7c.jpg)
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:
[`catplot()`](seaborn.catplot.html#seaborn.catplot "seaborn.catplot") to combine [`boxenplot()`](#seaborn.boxenplot "seaborn.boxenplot") 以及 [`FacetGrid`](seaborn.FacetGrid.html#seaborn.FacetGrid "seaborn.FacetGrid") 结合起来使用。这允许您通过额外的分类变量进行分组。使用 [`catplot()`](seaborn.catplot.html#seaborn.catplot "seaborn.catplot") 比直接使用 [`FacetGrid`](seaborn.FacetGrid.html#seaborn.FacetGrid "seaborn.FacetGrid") 更为安全,因为它保证了不同切面上变量同步的顺序:
```py
>>> g = sns.catplot(x="sex", y="total_bill",
......@@ -178,4 +180,4 @@ Use [`catplot()`](seaborn.catplot.html#seaborn.catplot "seaborn.catplot") to com
```
![http://seaborn.pydata.org/_images/seaborn-boxenplot-8.png](img/ef97d95b2084af9b8636c2514545289d.jpg)
\ No newline at end of file
![http://seaborn.pydata.org/_images/seaborn-boxenplot-8.png](img/ef97d95b2084af9b8636c2514545289d.jpg)
# seaborn.pointplot
> 译者:[FindNorthStar](https://github.com/FindNorthStar)
```py
seaborn.pointplot(x=None, y=None, hue=None, data=None, order=None, hue_order=None, estimator=<function mean>, ci=95, n_boot=1000, units=None, markers='o', linestyles='-', dodge=False, join=True, scale=1, orient=None, color=None, palette=None, errwidth=None, capsize=None, ax=None, **kwargs)
```
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.
重要的一点是点图仅显示平均值(或其他估计值),但在许多情况下,显示分类变量的每个级别的值的分布可能会带有更多信息。在这种情况下,其他绘图方法,例如箱型图或小提琴图可能更合适。
Input data can be passed in a variety of formats, including:
输入数据可以通过多种格式传入,包括:
* 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.
* An array or list of vectors.
* 格式为列表,numpy数组或pandas Series对象的数据向量可以直接传递给`x``y``hue`参数。
* 对于长格式的DataFrame,`x``y`,和`hue`参数会决定如何绘制数据。
* 对于宽格式的DataFrame,每一列数值列都会被绘制。
* 一个数组或向量的列表。
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.
在大多数情况下,可以使用numpy或Python对象,但更推荐使用pandas对象,因为与数据关联的列名/行名可以用于标注横轴/纵轴的名称。此外,您可以使用分类类型对变量进行分组以控制绘图元素的顺序。
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.
此函数始终将其中一个变量视为分类,并在相关轴上的序数位置(0,1,... n)处绘制数据,即使数据属于数值类型或日期类型也是如此。
See the [tutorial](../tutorial/categorical.html#categorical-tutorial) for more information.
更多信息请参阅 [教程](../tutorial/categorical.html#categorical-tutorial)
参数:`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.
> 控制绘图的方向(垂直或水平)。这通常是从输入变量的dtype推断出来的,但是当“分类”变量为数值型或绘制宽格式数据时可用于指定绘图的方向。
`estimator`callable that maps vector -&gt; scalar, optional
`estimator`调用函数实现向量 -&gt; 标量的映射,可选
> 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.
> 在估计值附近绘制置信区间的尺寸大小。如果是“sd”,则跳过引导阶段并绘制观察数据点的标准差。如果为 `None`,则不会执行引导过程,并且不会绘制误差块。
`n_boot`:int, optional
`n_boot`:int,可选
> 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” &#124; “h”, optional
`orient`:“v” &#124; “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.
> 控制绘图的方向(垂直或水平)。这通常是从输入变量的dtype推断出来的,但是当“分类”变量为数值型或绘制宽格式数据时可用于指定绘图的方向。
`color`:matplotlib color, optional
`color`:matplotlib颜色,可选
> 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.
> 用于`hue`变量的不同级别的颜色。可以从 [`color_palette()`](seaborn.color_palette.html#seaborn.color_palette "seaborn.color_palette") 得到一些解释,或者将色调级别映射到matplotlib颜色的字典。
`errwidth`:float, optional
`errwidth`:float,可选
> Thickness of error bar lines (and caps).
> 误差线(和上下限指示线)的厚度。
`capsize`:float, optional
`capsize`:float,可选
> Width of the “caps” on error bars.
> 误差线“上下限指示线”的宽度。
`ax`:matplotlib Axes, optional
`ax`:matplotlib轴,可选
> Axes object to draw the plot onto, otherwise uses the current Axes.
> 绘图时使用的Axes轴对象,否则使用当前Axes轴对象。
返回值:`ax`:matplotlib Axes
返回值:`ax`:matplotlib
> Returns the Axes object with the plot drawn onto it.
> 返回Axes对轴象,并在其上绘制绘图。
See also
亦可参见
Show point estimates and confidence intervals using bars.Combine a categorical plot with a class:<cite>FacetGrid</cite>.
使用线条显示数据点的估计值和置信区间。将分类类别的绘图与该类结合使用:<cite>FacetGrid</cite>
Examples
示例
Draw a set of vertical point plots grouped by a categorical variable:
绘制一组按分类变量分组的纵向点图:
```py
>>> import seaborn as sns
......@@ -122,7 +124,7 @@ Draw a set of vertical point plots grouped by a categorical variable:
![http://seaborn.pydata.org/_images/seaborn-pointplot-1.png](img/f5eb9519edb052868537ca9735f0f8df.jpg)
Draw a set of vertical points with nested grouping by a two variables:
通过两个嵌套分组的变量绘制一组纵向的点图:
```py
>>> ax = sns.pointplot(x="time", y="total_bill", hue="smoker",
......@@ -132,7 +134,7 @@ Draw a set of vertical points with nested grouping by a two variables:
![http://seaborn.pydata.org/_images/seaborn-pointplot-2.png](img/864eda3b3c2fcc6b0bdb53c84c3dafcf.jpg)
Separate the points for different hue levels along the categorical axis:
沿着分类轴分离不同色调级别的点:
```py
>>> ax = sns.pointplot(x="time", y="total_bill", hue="smoker",
......@@ -142,7 +144,7 @@ Separate the points for different hue levels along the categorical axis:
![http://seaborn.pydata.org/_images/seaborn-pointplot-3.png](img/b7f6772294dcf0d9b7035314c114c54b.jpg)
Use a different marker and line style for the hue levels:
根据色调级别使用不同的标记和线条样式:
```py
>>> ax = sns.pointplot(x="time", y="total_bill", hue="smoker",
......@@ -154,7 +156,7 @@ Use a different marker and line style for the hue levels:
![http://seaborn.pydata.org/_images/seaborn-pointplot-4.png](img/a97ae4389fc8bc946eb62e06c173b3e3.jpg)
Draw a set of horizontal points:
绘制一组横向的点图:
```py
>>> ax = sns.pointplot(x="tip", y="day", data=tips)
......@@ -163,7 +165,7 @@ Draw a set of horizontal points:
![http://seaborn.pydata.org/_images/seaborn-pointplot-5.png](img/4217fbfe6aaba42c4d18a69c5b8c9fc4.jpg)
Don’t draw a line connecting each point:
不要绘制每个点的连接线:
```py
>>> ax = sns.pointplot(x="tip", y="day", data=tips, join=False)
......@@ -172,7 +174,7 @@ Don’t draw a line connecting each point:
![http://seaborn.pydata.org/_images/seaborn-pointplot-6.png](img/96a33f32e85dcced62c9fc4ff063fe3d.jpg)
Use a different color for a single-layer plot:
对单层图使用不同的颜色:
```py
>>> ax = sns.pointplot("time", y="total_bill", data=tips,
......@@ -182,7 +184,7 @@ Use a different color for a single-layer plot:
![http://seaborn.pydata.org/_images/seaborn-pointplot-7.png](img/1e3348f06e5cd7876d5bc530b04d3d93.jpg)
Use a different color palette for the points:
为数据点使用不同的调色板:
```py
>>> ax = sns.pointplot(x="time", y="total_bill", hue="smoker",
......@@ -192,7 +194,7 @@ Use a different color palette for the points:
![http://seaborn.pydata.org/_images/seaborn-pointplot-8.png](img/d4a4eeea79c55b0ae9d3088746b6503a.jpg)
Control point order by passing an explicit order:
通过显式传入参数指定顺序控制点的显示顺序:
```py
>>> ax = sns.pointplot(x="time", y="tip", data=tips,
......@@ -202,7 +204,7 @@ Control point order by passing an explicit order:
![http://seaborn.pydata.org/_images/seaborn-pointplot-9.png](img/4c08e24283b6829b3d91e3c23de56923.jpg)
Use median as the estimate of central tendency:
用中位数作为集中趋势的估计:
```py
>>> from numpy import median
......@@ -212,7 +214,7 @@ Use median as the estimate of central tendency:
![http://seaborn.pydata.org/_images/seaborn-pointplot-10.png](img/0ec9398faa407996527db66db46c71f2.jpg)
Show the standard error of the mean with the error bars:
用误差线显示均值的标准误差:
```py
>>> ax = sns.pointplot(x="day", y="tip", data=tips, ci=68)
......@@ -221,7 +223,7 @@ Show the standard error of the mean with the error bars:
![http://seaborn.pydata.org/_images/seaborn-pointplot-11.png](img/f9f6dd93a512624527b38dcc26d97e37.jpg)
Show standard deviation of observations instead of a confidence interval:
显示观测值的标准偏差而不是置信区间:
```py
>>> ax = sns.pointplot(x="day", y="tip", data=tips, ci="sd")
......@@ -230,7 +232,7 @@ Show standard deviation of observations instead of a confidence interval:
![http://seaborn.pydata.org/_images/seaborn-pointplot-12.png](img/f41526e37f8f11614ea339da0e242c51.jpg)
Add “caps” to the error bars:
将“上下限指示线”增加到误差线的顶部和底部:
```py
>>> ax = sns.pointplot(x="day", y="tip", data=tips, capsize=.2)
......@@ -239,7 +241,7 @@ Add “caps” to the error bars:
![http://seaborn.pydata.org/_images/seaborn-pointplot-13.png](img/b7df4cf62c681ea39bd145bdb740bc81.jpg)
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:
[`catplot()`](seaborn.catplot.html#seaborn.catplot "seaborn.catplot")[`barplot()`](seaborn.barplot.html#seaborn.barplot "seaborn.barplot") 以及 [`FacetGrid`](seaborn.FacetGrid.html#seaborn.FacetGrid "seaborn.FacetGrid")结合使用。这允许您通过额外的分类变量进行分组。使用 [`catplot()`](seaborn.catplot.html#seaborn.catplot "seaborn.catplot") 比直接使用 [`FacetGrid`](seaborn.FacetGrid.html#seaborn.FacetGrid "seaborn.FacetGrid") 更为安全,因为它保证了不同切面上变量同步的顺序:
```py
>>> g = sns.catplot(x="sex", y="total_bill",
......
......@@ -4,109 +4,108 @@
seaborn.barplot(x=None, y=None, hue=None, data=None, order=None, hue_order=None, estimator=<function mean>, ci=95, n_boot=1000, units=None, orient=None, color=None, palette=None, saturation=0.75, errcolor='.26', errwidth=None, capsize=None, dodge=True, ax=None, **kwargs)
```
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.
条形图用每个矩形的高度来表示数值变量的集中趋势的估计值,并提供误差条来显示估计值得不确定度。条形图的纵轴是从零开始的,这对于0值是有意义的情况是非常好的。
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.
要注意的是,条形图只显示平均值(或者其他的估计值),但是在大部分情况下,展示数值在不同分类变量上的分布会更有用。如果要表示出数据的分布,用箱型图或者小提琴图会更恰当。
Input data can be passed in a variety of formats, including:
输入数据的格式可以不同,包括:
* 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.
* An array or list of vectors.
* 以列表,numpy array或者pandas中的Series object 表示的向量。这些向量可以直接传入 `x`, `y`, 以及 `hue` 参数。
* 长表, x值,y值和色相变量决定了数据是如何绘制的。
* 宽表,每个列的数值都会被绘制出来.
* 数组或者列表的向量。
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.
大多数情况下,您可以使用numpy的对象或者python的对象,但是用pandas对象更好,因为相关的列名会被标注在图标上。 另外,为了控制绘图元素 您也可以可以用分类类型来组合不同的变量。
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.
这个函数始终把一个变量当做分类变量,即使这个数据是数值类型或者日期类型,并且按照序数顺序绘制在相关的轴上。
See the [tutorial](../tutorial/categorical.html#categorical-tutorial) for more information.
详情请看[教程](../tutorial/categorical.html#categorical-tutorial)
参数:`x, y, hue`names of variables in `data` or vector data, optional
参数:`x, y, hue``data` 中的变量名词或者向量, optional
> Inputs for plotting long-form data. See examples for interpretation.
> 用于绘制long-form数据的变量名称.
`data`:DataFrame, array, or list of arrays, optional
`data`:DataFrame, 数组, 数组列表, optional
> 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,数据集会被认为是long-form,否则会被认为是wide-form。
`order, hue_order`lists of strings, optional
`order, hue_order`字符串列表, optional
> Order to plot the categorical levels in, otherwise the levels are inferred from the data objects.
> 绘制类别变量的顺序,如果没有,则从数据对象中推断绘图顺序。
`estimator`callable that maps vector -&gt; scalar, optional
`estimator`映射向量 -&gt; 标量, 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.
> 估计值周围的置信区间大小。如果输入的是 “sd”(标准差),会跳过bootstrapping的过程,只绘制数据的标准差。 如果输入是的是`None`, 不会执行botstrapping,而且错误条也不会绘制。
`n_boot`:int, optional
> 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” &#124; “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`:matplotlib color, optional
> 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.
> 不同级别的 `hue` 变量的颜色。 颜色要能被 [`color_palette()`]解释(seaborn.color_palette.html#seaborn.color_palette "seaborn.color_palette"), 或者一个能映射到matplotlib颜色的字典。
`saturation`:float, optional
> 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>.
显示每个分类bin中的观察计数。使用散点图图示符显示点估计和置信区间。将分类图与类相结合:<cite>FacetGrid</cite>.
Examples
Draw a set of vertical bar plots grouped by a categorical variable:
绘制一组按类别变量分组的垂直条形图:
```py
>>> import seaborn as sns
......@@ -118,7 +117,7 @@ Draw a set of vertical bar plots grouped by a categorical variable:
![http://seaborn.pydata.org/_images/seaborn-barplot-1.png](img/9d1addc98b6a35ef0376219c56e7b7fd.jpg)
Draw a set of vertical bars with nested grouping by a two variables:
绘制一组由两个变量嵌套分组的垂直条形图:
```py
>>> ax = sns.barplot(x="day", y="total_bill", hue="sex", data=tips)
......@@ -127,7 +126,7 @@ Draw a set of vertical bars with nested grouping by a two variables:
![http://seaborn.pydata.org/_images/seaborn-barplot-2.png](img/863249efe2403afa4fae2f2b6884d3bd.jpg)
Draw a set of horizontal bars:
绘制一组水平条形图:
```py
>>> ax = sns.barplot(x="tip", y="day", data=tips)
......@@ -136,7 +135,7 @@ Draw a set of horizontal bars:
![http://seaborn.pydata.org/_images/seaborn-barplot-3.png](img/c3ea6265eaff0a4bfaec2966088cb66f.jpg)
Control bar order by passing an explicit order:
通过传入一个显式的顺序来控制条柱的顺序:
```py
>>> ax = sns.barplot(x="time", y="tip", data=tips,
......@@ -146,7 +145,7 @@ Control bar order by passing an explicit order:
![http://seaborn.pydata.org/_images/seaborn-barplot-4.png](img/9233554272a5e436f6ab85c97a65010c.jpg)
Use median as the estimate of central tendency:
用中值来评估数据的集中趋势:
```py
>>> from numpy import median
......@@ -156,7 +155,7 @@ Use median as the estimate of central tendency:
![http://seaborn.pydata.org/_images/seaborn-barplot-5.png](img/2622373fb99932aa42e45c3b151135be.jpg)
Show the standard error of the mean with the error bars:
用误差条显示平均值的标准误差:
```py
>>> ax = sns.barplot(x="day", y="tip", data=tips, ci=68)
......@@ -165,7 +164,7 @@ Show the standard error of the mean with the error bars:
![http://seaborn.pydata.org/_images/seaborn-barplot-6.png](img/d1310bd7e87a8549d1f0b3a1479fc06d.jpg)
Show standard deviation of observations instead of a confidence interval:
展示数据的标准差:
```py
>>> ax = sns.barplot(x="day", y="tip", data=tips, ci="sd")
......@@ -174,7 +173,7 @@ Show standard deviation of observations instead of a confidence interval:
![http://seaborn.pydata.org/_images/seaborn-barplot-7.png](img/eeb77dac6d8f76d9f715476ce03773c5.jpg)
Add “caps” to the error bars:
给误差条增加“端点”:
```py
>>> ax = sns.barplot(x="day", y="tip", data=tips, capsize=.2)
......@@ -183,7 +182,7 @@ Add “caps” to the error bars:
![http://seaborn.pydata.org/_images/seaborn-barplot-8.png](img/5a69e1058d9b8b4b5be6dc15d1bad130.jpg)
Use a different color palette for the bars:
使用一个不同的调色盘来绘制图案:
```py
>>> ax = sns.barplot("size", y="total_bill", data=tips,
......@@ -193,7 +192,7 @@ Use a different color palette for the bars:
![http://seaborn.pydata.org/_images/seaborn-barplot-9.png](img/ef011fca38d3c55dde21ee8363e93e61.jpg)
Use `hue` without changing bar position or width:
在不改变条柱的位置或者宽度的前提下,使用 `hue` :
```py
>>> tips["weekend"] = tips["day"].isin(["Sat", "Sun"])
......@@ -204,7 +203,7 @@ Use `hue` without changing bar position or width:
![http://seaborn.pydata.org/_images/seaborn-barplot-10.png](img/d38d4ad12b16322a5ed00690bcbcd8b6.jpg)
Plot all bars in a single color:
用同一种颜色绘制所有条柱:
```py
>>> ax = sns.barplot("size", y="total_bill", data=tips,
......@@ -214,7 +213,7 @@ Plot all bars in a single color:
![http://seaborn.pydata.org/_images/seaborn-barplot-11.png](img/4922c693b75b7656b2f16f8fd2dd6509.jpg)
Use `plt.bar` keyword arguments to further change the aesthetic:
`plt.bar` 关键字参数进一步改变图表的样式:
```py
>>> ax = sns.barplot("day", "total_bill", data=tips,
......@@ -225,7 +224,7 @@ Use `plt.bar` keyword arguments to further change the aesthetic:
![http://seaborn.pydata.org/_images/seaborn-barplot-12.png](img/20114eb58ca40a3ccf0b20f14f426c83.jpg)
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:
使用 [`catplot()`](seaborn.catplot.html#seaborn.catplot "seaborn.catplot") 来结合 [`barplot()`](#seaborn.barplot "seaborn.barplot")[`FacetGrid`](seaborn.FacetGrid.html#seaborn.FacetGrid "seaborn.FacetGrid"). 这允许数据根据额外的类别变量分组。使用 [`catplot()`](seaborn.catplot.html#seaborn.catplot "seaborn.catplot") 比直接使用 [`FacetGrid`](seaborn.FacetGrid.html#seaborn.FacetGrid "seaborn.FacetGrid") 更安全, 因为它可以确保变量在不同的facet之间保持同步:
```py
>>> g = sns.catplot(x="sex", y="total_bill",
......@@ -235,4 +234,4 @@ Use [`catplot()`](seaborn.catplot.html#seaborn.catplot "seaborn.catplot") to com
```
![http://seaborn.pydata.org/_images/seaborn-barplot-13.png](img/a2d8b9c6867b1006b56e5508d5472c86.jpg)
\ No newline at end of file
![http://seaborn.pydata.org/_images/seaborn-barplot-13.png](img/a2d8b9c6867b1006b56e5508d5472c86.jpg)
# seaborn.distplot
> 译者:[hyuuo](https://github.com/hyuuo)
```py
seaborn.distplot(a, bins=None, hist=True, kde=True, rug=False, fit=None, hist_kws=None, kde_kws=None, rug_kws=None, fit_kws=None, color=None, vertical=False, norm_hist=False, axlabel=None, label=None, ax=None)
```
......
# seaborn.kdeplot
> 译者:[hyuuo](https://github.com/hyuuo)
```py
seaborn.kdeplot(data, data2=None, shade=False, vertical=False, kernel='gau', bw='scott', gridsize=100, cut=3, clip=None, legend=True, cumulative=False, shade_lowest=True, cbar=False, cbar_ax=None, cbar_kws=None, ax=None, **kwargs)
```
......
# seaborn.rugplot
> 译者:[P3n9W31](https://github.com/P3n9W31)
```py
seaborn.rugplot(a, height=0.05, axis='x', ax=None, **kwargs)
```
Plot datapoints in an array as sticks on an axis.
将数组中的数据点绘制为轴上的棒状标识。
参数:`a`vector
参数:`a`向量
> 1D array of observations.
> 1维的观察数组。
`height`scalar, optional
`height`标量, 可选
> Height of ticks as proportion of the axis.
> 以比例形式表示的坐标轴上棒状标识的高度。
`axis`:{‘x’ &#124; ‘y’}, optional
`axis`:{‘x’ &#124; ‘y’}, 可选
> Axis to draw rugplot on.
> 需要画rugplot的坐标轴
`ax`:matplotlib axes, optional
`ax`:matplotlib 轴, 可选
> Axes to draw plot into; otherwise grabs current axes.
> 进行绘制的坐标轴; 未指定的话设定为当前轴。
`kwargs`key, value pairings
`kwargs`键值对
> Other keyword arguments are passed to `LineCollection`.
> 被传递给`LineCollection`的其他关键字参数。
返回值:`ax`:matplotlib axes
返回值:`ax`:matplotlib Axex对象
> The Axes object with the plot on it.
> 在其上进行绘图的Axex对象。
# seaborn.lmplot
> 译者:[P3n9W31](https://github.com/P3n9W31)
```py
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.
在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.
这个函数结合了 [`regplot()`](seaborn.regplot.html#seaborn.regplot "seaborn.regplot")[`FacetGrid`](seaborn.FacetGrid.html#seaborn.FacetGrid "seaborn.FacetGrid")。 它预期作为一个能够将回归模型运用在数据集处于不同条件下的子数据集的方便的接口
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.
在考虑如何将变量分配到不同方面时,一般规则是使用 `hue` 进行最重要的比较,然后使用 `col``row `。 但是,请始终考虑您的特定数据集以及您正在创建的可视化目标。
There are a number of mutually exclusive options for estimating the regression model. See the [tutorial](../tutorial/regression.html#regression-tutorial) for more information.
估算回归模型有许多互斥的选项。 有关详细信息,请参阅 [tutorial](../tutorial/regression.html#regression-tutorial)
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.
此函数的参数涵盖了 [`FacetGrid`](seaborn.FacetGrid.html#seaborn.FacetGrid "seaborn.FacetGrid")中的大多数选项,尽管这样,偶尔还是会出现您需要直接使用该类和 [`regplot()`](seaborn.regplot.html#seaborn.regplot "seaborn.regplot") 的情况。
参数:`x, y`strings, optional
参数:`x, y`字符串,可选
> Input variables; these should be column names in `data`.
> 输入变量; 这些应该是`data`中的列名。
`data`:DataFrame
> Tidy (“long-form”) dataframe where each column is a variable and each row is an observation.
> Tidy (“long-form”)格式的DataFrame,其中每列为一个变量,每行为一个观测样本。
`hue, col, row`strings
`hue, col, row`字符串
> 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.
> 定义数据子集的变量,将在网格中的不同构面上绘制。 请参阅`* _order`参数以控制此变量的级别顺序。
`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.
> 用于`hue`变量的不同级别的颜色。 应该是 [`color_palette()`](seaborn.color_palette.html#seaborn.color_palette "seaborn.color_palette")可以解释的东西,或者是将色调级别映射到matplotlib颜色的字典。
`col_wrap`int, optional
`col_wrap`整数,可选
> “Wrap” the column variable at this width, so that the column facets span multiple rows. Incompatible with a `row` facet.
> 以此宽度“包裹”列变量,以便列分面(facet)跨越多行。 与`row` 分面(facet)不兼容。
`height`scalar, optional
`height` 标量,可选
> Height (in inches) of each facet. See also: `aspect`.
> 每个分面(facet)的高度(以英寸为单位)。 另见:`aspect`。
`aspect`scalar, optional
`aspect`标量,可选
> Aspect ratio of each facet, so that `aspect * height` gives the width of each facet in inches.
> 每个分面(facet)的纵横比,因此`aspect * height`给出每个分面(facet)的宽度,单位为英寸。
`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.
> 分面变量的级别顺序。在默认情况下,这将是级别在“data”中出现的顺序,或者,如果变量是pandas的分类类别变量,则为类别的顺序。
`legend`bool, optional
`legend`布尔值,可选
> 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 -&gt; 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.
> 将此函数应用于`x`的每个唯一值并绘制结果的估计值。当`x`是离散变量时,这是十分有用的。如果给出`x_ci`,则该估计将被引导并且将绘制置信区间。
`x_bins`int or vector, optional
`x_bins`整数或向量,可选
> 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`变量加入离散区间,然后估计中心趋势和置信区间。 此分箱仅影响散点图的绘制方式; 回归仍然适合原始数据。该参数被解释为均匀大小(不必要间隔)的箱的数量或箱中心的位置。使用此参数时,它意味着`x_estimator`的默认值为`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.
> 绘制“x”离散值的集中趋势时使用的置信区间的大小。 如果为`“ci”`,遵循`ci`参数的值。 如果是“sd”,则跳过bootstrapping并显示每个bin中观察值的标准偏差。
`scatter`bool, optional
`scatter`布尔值,可选
> 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.
> 回归估计的置信区间的大小。这将使用回归线周围的半透明带绘制。 使用自助法(bootstrap)估计置信区间; 对于大型数据集,建议通过将此参数设置为None来避免该计算。
`n_boot`int, optional
`n_boot`整数,可选
> 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.
> 用于估计`ci`的自助法(bootstrap)重采样数。 默认值试图在时间和稳定性之间找到平衡; 你可能希望为“最终”版本的图像增加此值。
`units`variable name in `data`, optional
`units``data`中的变量名,可选
> 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.
> 如果`x`和`y`观察结果嵌套在采样单元中,则可以在此处指定。在通过对所有的单元和观察样本(在单元内)执行重新采样的多级自助法(multilevel bootstrap)来计算置信区间时将考虑这一点。 否则,这不会影响估计或绘制回归的方式。
`order`int, optional
`order`整数,可选
> 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.
> 如果为“True”,则假设`y`是二元变量并使用`statsmodels`来估计逻辑回归模型。 请注意,这比线性回归的计算密集程度要大得多,因此您可能希望减少引导程序重新采样(`n_boot`)的数量或将 `ci`设置为“无”。
`lowess`bool, optional
`lowess`布尔值,可选
> 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.
> 如果为“True”,则使用`statsmodels`来估计非参数lowess模型(局部加权线性回归)。 请注意,目前无法为此类模型绘制置信区间。
`robust`bool, optional
`robust`布尔值,可选
> 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.
> 如果为“True”,则使用`statsmodels`来估计稳健回归。 这将削弱异常值。 请注意,这比标准线性回归的计算密集程度要大得多,因此您可能希望减少引导程序重新采样(`n_boot`)的数量或将 `ci`设置为“无”。
`logx`bool, optional
`logx`布尔值,可选
> 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.
> 如果为 `True`,则估计形式y~log(x)的线性回归,但在输入空间中绘制散点图和回归模型。 请注意,`x`必须为正才能正常工作。
`{x,y}_partial`strings in `data` or matrices
`{x,y}_partial` `data`中的字符串或矩阵
> 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.
> 默认情况下,绘制回归线以在绘制散点图后填充x轴限制。 如果`truncate`是`True`,它将改为受到数据本身限制的限制。
`{x,y}_jitter`floats, optional
`{x,y}_jitter`浮点数,可选
> 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.
> 将此大小的均匀随机噪声添加到“x”或“y”变量中。 在拟合回归之后,噪声被添加到数据的副本中,并且仅影响散点图的外观。 在绘制采用离散值的变量时,这会很有用。
`{scatter,line}_kws`dictionaries
`{scatter,line}_kws`字典
> 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"`).
绘制数据和条件模型fit.Subplot网格用于绘制条件关系。合并 [`regplot()`](seaborn.regplot.html#seaborn.regplot "seaborn.regplot")[`PairGrid`](seaborn.PairGrid.html#seaborn.PairGrid "seaborn.PairGrid") (与`kind =“reg”`一起使用时)。
Notes
注意
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").
[`regplot()`](seaborn.regplot.html#seaborn.regplot "seaborn.regplot")[`lmplot()`](#seaborn.lmplot "seaborn.lmplot") 函数是紧密关联的,但是前者是一个坐标轴级别的函数,而后者则是一个联合了[`regplot()`](seaborn.regplot.html#seaborn.regplot "seaborn.regplot")[`FacetGrid `](seaborn.FacetGrid.html#seaborn.FacetGrid "seaborn.FacetGrid")的图像级别的函数。
Examples
示例
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.
这些例子集中在基本的回归模型图上,以展示各种方面的选项; 请参阅 [`regplot()`](seaborn.regplot.html#seaborn.regplot "seaborn.regplot") 文档,以演示绘制数据和模型的其他选项。 还有其他一些如何使用 [`FacetGrid`](seaborn.FacetGrid.html#seaborn.FacetGrid "seaborn.FacetGrid") 文档中的返回对象操作绘图的示例。
Plot a simple linear relationship between two variables:
绘制两个变量之间的简单线性关系:
```py
>>> import seaborn as sns; sns.set(color_codes=True)
......@@ -155,7 +157,7 @@ Plot a simple linear relationship between two variables:
![http://seaborn.pydata.org/_images/seaborn-lmplot-1.png](img/86032eef9f0a340dfa9834cee96b10d4.jpg)
Condition on a third variable and plot the levels in different colors:
条件在第三个变量上并绘制不同颜色的水平:
```py
>>> g = sns.lmplot(x="total_bill", y="tip", hue="smoker", data=tips)
......@@ -164,7 +166,7 @@ Condition on a third variable and plot the levels in different colors:
![http://seaborn.pydata.org/_images/seaborn-lmplot-2.png](img/ed002aaba578f2b1a6ae8d4677a52900.jpg)
Use different markers as well as colors so the plot will reproduce to black-and-white more easily:
使用不同的标记和颜色,以便绘图更容易再现为黑白:
```py
>>> g = sns.lmplot(x="total_bill", y="tip", hue="smoker", data=tips,
......@@ -174,7 +176,7 @@ Use different markers as well as colors so the plot will reproduce to black-and-
![http://seaborn.pydata.org/_images/seaborn-lmplot-3.png](img/770464118d2458a098652af00c46525a.jpg)
Use a different color palette:
使用不同的调色板:
```py
>>> g = sns.lmplot(x="total_bill", y="tip", hue="smoker", data=tips,
......@@ -184,7 +186,7 @@ Use a different color palette:
![http://seaborn.pydata.org/_images/seaborn-lmplot-4.png](img/a314683a7f14a4e8a552aca52002c9b5.jpg)
Map `hue` levels to colors with a dictionary:
使用字典将`hue`级别映射到颜色:
```py
>>> g = sns.lmplot(x="total_bill", y="tip", hue="smoker", data=tips,
......@@ -194,7 +196,7 @@ Map `hue` levels to colors with a dictionary:
![http://seaborn.pydata.org/_images/seaborn-lmplot-5.png](img/cc594c98f73700b14c9817d68ebc89c6.jpg)
Plot the levels of the third variable across different columns:
绘制不同列中第三个变量的级别:
```py
>>> g = sns.lmplot(x="total_bill", y="tip", col="smoker", data=tips)
......@@ -203,7 +205,7 @@ Plot the levels of the third variable across different columns:
![http://seaborn.pydata.org/_images/seaborn-lmplot-6.png](img/3c50ee123e8192e2899983b1be19d34b.jpg)
Change the height and aspect ratio of the facets:
更改构面的高度和纵横比:
```py
>>> g = sns.lmplot(x="size", y="total_bill", hue="day", col="day",
......@@ -213,7 +215,7 @@ Change the height and aspect ratio of the facets:
![http://seaborn.pydata.org/_images/seaborn-lmplot-7.png](img/47ce7b8d629a8d762bea59bc674e5490.jpg)
Wrap the levels of the column variable into multiple rows:
将列变量的级别换行为多行:
```py
>>> g = sns.lmplot(x="total_bill", y="tip", col="day", hue="day",
......@@ -223,7 +225,7 @@ Wrap the levels of the column variable into multiple rows:
![http://seaborn.pydata.org/_images/seaborn-lmplot-8.png](img/798a1691371e0506570d9f1f72d95fe4.jpg)
Condition on two variables to make a full grid:
两个变量上的条件形成一个完整的网格:
```py
>>> g = sns.lmplot(x="total_bill", y="tip", row="sex", col="time",
......@@ -233,7 +235,7 @@ Condition on two variables to make a full grid:
![http://seaborn.pydata.org/_images/seaborn-lmplot-9.png](img/36048a5d4503fddb7cf3479a473188f2.jpg)
Use methods on the returned [`FacetGrid`](seaborn.FacetGrid.html#seaborn.FacetGrid "seaborn.FacetGrid") instance to further tweak the plot:
在返回的 [`FacetGrid`](seaborn.FacetGrid.html#seaborn.FacetGrid "seaborn.FacetGrid") 实例上使用方法来进一步调整图像:
```py
>>> g = sns.lmplot(x="total_bill", y="tip", row="sex", col="time",
......
# seaborn.regplot
> 译者:[P3n9W31](https://github.com/P3n9W31)
```py
seaborn.regplot(x, y, data=None, 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, dropna=True, x_jitter=None, y_jitter=None, label=None, color=None, marker='o', scatter_kws=None, line_kws=None, ax=None)
```
Plot data and a linear regression model fit.
绘制数据和线性回归模型拟合。
There are a number of mutually exclusive options for estimating the regression model. See the [tutorial](../tutorial/regression.html#regression-tutorial) for more information.
估算回归模型有许多互斥的选项。查看这个[教程](../tutorial/regression.html#regression-tutorial) 来了解更多的信息。
参数:**x, y:string, series, or vector array**
参数:**x,y:字符串,序列(series)或者是向量数组(vector array)**
> 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.
> 输入变量。 如果是字符串,应该与`data`中的列名相对应。 使用pandas对象时,轴将被Series的名字标记。
`data`:DataFrame
> Tidy (“long-form”) dataframe where each column is a variable and each row is an observation.
> Tidy (“long-form”)格式的DataFrame,其中每列为一个变量,每行为一个观测样本。
`x_estimator`callable that maps vector -&gt; scalar, optional
`x_estimator`可调用的映射向量 -&gt;标量,可选
> 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.
> 将此函数应用于`x`的每个唯一值并绘制结果的估计值。当`x`是离散变量时,这是十分有用的。如果给出`x_ci`,则该估计将被引导并且将绘制置信区间。
`x_bins`int or vector, optional
`x_bins`整数或向量,可选
> 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`变量加入离散区间,然后估计中心趋势和置信区间。 此分箱仅影响散点图的绘制方式; 回归仍然适合原始数据。该参数被解释为均匀大小(不必要间隔)的箱的数量或箱中心的位置。使用此参数时,它意味着`x_estimator`的默认值为`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.
> 绘制“x”离散值的集中趋势时使用的置信区间的大小。 如果为`“ci”`,遵循`ci`参数的值。 如果是“sd”,则跳过bootstrapping并显示每个bin中观察值的标准偏差。
`scatter`bool, optional
`scatter`布尔值,可选
> 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.
> 回归估计的置信区间的大小。这将使用回归线周围的半透明带绘制。 使用自助法(bootstrap)估计置信区间; 对于大型数据集,建议通过将此参数设置为None来避免该计算。
`n_boot`int, optional
`n_boot`整数,可选
> 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.
> 用于估计`ci`的自助法(bootstrap)重采样数。 默认值试图在时间和稳定性之间找到平衡; 你可能希望为“最终”版本的图像增加此值。
`units`variable name in `data`, optional
`units` `data`,中的变量名,可选
> 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.
> 如果`x`和`y`观察结果嵌套在采样单元中,则可以在此处指定。在通过对所有的单元和观察样本(在单元内)执行重新采样的多级自助法(multilevel bootstrap)来计算置信区间时将考虑这一点。 否则,这不会影响估计或绘制回归的方式。
`order`int, optional
`order`整数,可选
> 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.
> 如果为“True”,则假设`y`是二元变量并使用`statsmodels`来估计逻辑回归模型。 请注意,这比线性回归的计算密集程度要大得多,因此您可能希望减少引导程序重新采样(`n_boot`)的数量或将 `ci`设置为“无”。
`lowess`bool, optional
`lowess`布尔值,可选
> 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.
> 如果为“True”,则使用`statsmodels`来估计非参数lowess模型(局部加权线性回归)。 请注意,目前无法为此类模型绘制置信区间。
`robust`bool, optional
`robust`布尔值,可选
> 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.
> 如果为“True”,则使用`statsmodels`来估计稳健回归。 这将削弱异常值。 请注意,这比标准线性回归的计算密集程度要大得多,因此您可能希望减少引导程序重新采样(`n_boot`)的数量或将 `ci`设置为“无”。
`logx`bool, optional
`logx`布尔值,可选
> 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.
> 如果为 `True`,则估计形式y~log(x)的线性回归,但在输入空间中绘制散点图和回归模型。 请注意,`x`必须为正才能正常工作。
`{x,y}_partial`strings in `data` or matrices
`{x,y}_partial` `data` 中的字符串或矩阵
> 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.
> 默认情况下,绘制回归线以在绘制散点图后填充x轴限制。 如果`truncate`是`True`,它将改为受到数据本身限制的限制。
`{x,y}_jitter`floats, optional
`{x,y}_jitter`浮点数,可选
> 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.
> 将此大小的均匀随机噪声添加到“x”或“y”变量中。 在拟合回归之后,噪声被添加到数据的副本中,并且仅影响散点图的外观。 在绘制采用离散值的变量时,这会很有用。
`label`string
`label`字符串
> Label to apply to ether the scatterplot or regression line (if `scatter` is `False`) for use in a legend.
> 要应用于散点图或回归线(如果`scatter`为'False`)的标签,以便在图例中使用。
`color`:matplotlib color
`color`:matplotlib 颜色
> Color to apply to all plot elements; will be superseded by colors passed in `scatter_kws` or `line_kws`.
> 适用于所有绘图元素的颜色; 将被`scatter_kws`或`line_kws`中传递的颜色取代。
`marker`:matplotlib marker code
`marker`:matplotlib标记代码或标记代码列表,可选
> Marker to use for the scatterplot glyphs.
> 散点图的标记。
`{scatter,line}_kws`dictionaries
`{scatter,line}_kws`字典
> 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.
结合 [`regplot()`](#seaborn.regplot "seaborn.regplot")[`FacetGrid`](seaborn.FacetGrid.html#seaborn.FacetGrid "seaborn.FacetGrid") 来绘制数据集中的多个线性关系。 结合 [`regplot()`](#seaborn.regplot "seaborn.regplot")[`JointGrid`](seaborn.JointGrid.html#seaborn.JointGrid "seaborn.JointGrid") (与`kind="reg"`一起使用时)。结合 [`regplot()`](#seaborn.regplot "seaborn.regplot")[`PairGrid`](seaborn.PairGrid.html#seaborn.PairGrid "seaborn.PairGrid") (当用于` kind =“reg”`)。绘制线性回归模型的残差。
Notes
注意
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").
[`regplot()`](#seaborn.regplot "seaborn.regplot")[`lmplot()`](seaborn.lmplot.html#seaborn.lmplot "seaborn.lmplot") 函数密切相关,但是前者是坐标轴级别的函数,而后者是结合了[`regplot()`](#seaborn.regplot "seaborn.regplot")[`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.
通过 [`jointplot()`](seaborn.jointplot.html#seaborn.jointplot "seaborn.jointplot")[`pairplot()`](seaborn.pairplot.html#seaborn.pairplot "seaborn.pairplot") 函数来组合 [`regplot()`](#seaborn.regplot "seaborn.regplot")[`JointGrid`](seaborn.JointGrid.html#seaborn.JointGrid "seaborn.JointGrid")[`PairGrid`](seaborn.PairGrid.html#seaborn.PairGrid "seaborn.PairGrid") 是十分容易的,虽然这些函数不直接接受所有 [`regplot()`](#seaborn.regplot "seaborn.regplot")的参数。
Examples
例子
Plot the relationship between two variables in a DataFrame:
绘制DataFrame中两个变量之间的关系:
```py
>>> import seaborn as sns; sns.set(color_codes=True)
......@@ -130,7 +132,7 @@ Plot the relationship between two variables in a DataFrame:
![http://seaborn.pydata.org/_images/seaborn-regplot-1.png](img/99b1873131479cf9f24377991b06cbdb.jpg)
Plot with two variables defined as numpy arrays; use a different color:
利用两个定义为numpy数组的变量进行绘图; 使用不同的颜色:
```py
>>> import numpy as np; np.random.seed(8)
......@@ -142,7 +144,7 @@ Plot with two variables defined as numpy arrays; use a different color:
![http://seaborn.pydata.org/_images/seaborn-regplot-2.png](img/b6422e805157f85b21973dd3266dcb3f.jpg)
Plot with two variables defined as pandas Series; use a different marker:
利用两个定义为pandas Series的变量来进行绘图; 使用不同的标记:
```py
>>> import pandas as pd
......@@ -153,7 +155,7 @@ Plot with two variables defined as pandas Series; use a different marker:
![http://seaborn.pydata.org/_images/seaborn-regplot-3.png](img/2749fd423c61cc0419daeeec8d8aa467.jpg)
Use a 68% confidence interval, which corresponds with the standard error of the estimate:
使用68%置信区间,该区间对应于估计的标准误差:
```py
>>> ax = sns.regplot(x=x, y=y, ci=68)
......@@ -162,7 +164,7 @@ Use a 68% confidence interval, which corresponds with the standard error of the
![http://seaborn.pydata.org/_images/seaborn-regplot-4.png](img/17710001d51c2a58f06feca00a0eaa56.jpg)
Plot with a discrete `x` variable and add some jitter:
使用离散的`x`变量进行绘图并添加一些抖动:
```py
>>> ax = sns.regplot(x="size", y="total_bill", data=tips, x_jitter=.1)
......@@ -171,7 +173,7 @@ Plot with a discrete `x` variable and add some jitter:
![http://seaborn.pydata.org/_images/seaborn-regplot-5.png](img/823e73942bde25e25637964d2bcd7acf.jpg)
Plot with a discrete `x` variable showing means and confidence intervals for unique values:
绘制一个离散的`x`变量,显示唯一值的均值和置信区间:
```py
>>> ax = sns.regplot(x="size", y="total_bill", data=tips,
......@@ -181,7 +183,7 @@ Plot with a discrete `x` variable showing means and confidence intervals for uni
![http://seaborn.pydata.org/_images/seaborn-regplot-6.png](img/b2bb1b6b97e36328f09b122b92dd52bf.jpg)
Plot with a continuous variable divided into discrete bins:
将连续的变量划分为分离的区间并进行绘图:
```py
>>> ax = sns.regplot(x=x, y=y, x_bins=4)
......@@ -190,7 +192,7 @@ Plot with a continuous variable divided into discrete bins:
![http://seaborn.pydata.org/_images/seaborn-regplot-7.png](img/90def53f341cf365a39051cbb1e17f61.jpg)
Fit a higher-order polynomial regression and truncate the model prediction:
拟合高阶多项式回归并截断模型预测:
```py
>>> ans = sns.load_dataset("anscombe")
......@@ -202,7 +204,7 @@ Fit a higher-order polynomial regression and truncate the model prediction:
![http://seaborn.pydata.org/_images/seaborn-regplot-8.png](img/1eb024fe4ee82e1fd71c47c29ebf1856.jpg)
Fit a robust regression and don’t plot a confidence interval:
拟合稳健回归并且不绘制置信区间:
```py
>>> ax = sns.regplot(x="x", y="y", data=ans.loc[ans.dataset == "III"],
......@@ -213,7 +215,7 @@ Fit a robust regression and don’t plot a confidence interval:
![http://seaborn.pydata.org/_images/seaborn-regplot-9.png](img/83369998db2c4eb1e99c856c538f5cb2.jpg)
Fit a logistic regression; jitter the y variable and use fewer bootstrap iterations:
对数据运用逻辑回归; 抖动y变量并使用较少的bootstrap迭代:
```py
>>> tips["big_tip"] = (tips.tip / tips.total_bill) > .175
......@@ -224,7 +226,7 @@ Fit a logistic regression; jitter the y variable and use fewer bootstrap iterati
![http://seaborn.pydata.org/_images/seaborn-regplot-10.png](img/b7d4fc0e5dd7fd0d56b558fc3316841a.jpg)
Fit the regression model using log(x) and truncate the model prediction:
使用 log(x) 拟合回归模型并截断模型预测:
```py
>>> ax = sns.regplot(x="size", y="total_bill", data=tips,
......
# seaborn.residplot
> 译者:[P3n9W31](https://github.com/P3n9W31)
```py
seaborn.residplot(x, y, data=None, lowess=False, x_partial=None, y_partial=None, order=1, robust=False, dropna=True, label=None, color=None, scatter_kws=None, line_kws=None, ax=None)
```
Plot the residuals of a linear regression.
绘制线性回归的残差。
此函数将在x上回归y(可能作为鲁棒或多项式回归),然后绘制残差的散点图。 你可以选择将局部加权回归散点平滑法(LOWESS)拟合到残差图,这有助于确定残差是否存在结构。
参数:`x`: 向量或字符串
> 预测变量数据中的数据或列名称。
`y`:向量或字符串
> 响应变量的数据中的数据或列名称。
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 &lt;cite&gt;data&lt;/cite&gt; for the predictor variable.
`lowess`: 布尔值, 可选
`y`:vector or string
> 将局部加权回归散点平滑法(LOWESS)应用到残差散点图中。
> Data or column name in &lt;cite&gt;data&lt;/cite&gt; for the response variable.
`{x, y}_partial`:矩阵或字符串,可选
`data`:DataFrame, optional
> 具有与x相同的第一维的矩阵或数据中的列名称。这些变量被视为有误的,并在绘制之前从x或y变量中删除。
> DataFrame to use if &lt;cite&gt;x&lt;/cite&gt; and &lt;cite&gt;y&lt;/cite&gt; 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 &lt;cite&gt;x&lt;/cite&gt;, or column name(s) in &lt;cite&gt;data&lt;/cite&gt;. These variables are treated as confounding and are removed from the &lt;cite&gt;x&lt;/cite&gt; or &lt;cite&gt;y&lt;/cite&gt; 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.
也可以看看
返回值:ax:matplotlib axes
[`regplot`](http://seaborn.pydata.org/generated/seaborn.regplot.html#seaborn.regplot)
> Axes with the regression plot.
绘制一个简单的线性回归模型
See also
[`jointplot`](http://seaborn.pydata.org/generated/seaborn.jointplot.html#seaborn.jointplot)
Plot a simple linear regression model.marginal distrbutions.
\ No newline at end of file
边际分布。
\ No newline at end of file
# seaborn.heatmap
> 译者:[hyuuo](https://github.com/hyuuo)
```py
seaborn.heatmap(data, vmin=None, vmax=None, cmap=None, center=None, robust=False, annot=None, fmt='.2g', annot_kws=None, linewidths=0, linecolor='white', cbar=True, cbar_kws=None, cbar_ax=None, square=False, xticklabels='auto', yticklabels='auto', mask=None, ax=None, **kwargs)
```
......
# seaborn.FacetGrid
> 译者:[hyuuo](https://github.com/hyuuo)
```py
class seaborn.FacetGrid(data, row=None, col=None, hue=None, col_wrap=None, sharex=True, sharey=True, height=3, aspect=1, palette=None, row_order=None, col_order=None, hue_order=None, hue_kws=None, dropna=True, legend_out=True, despine=True, margin_titles=False, xlim=None, ylim=None, subplot_kws=None, gridspec_kws=None, size=None)
```
......
# seaborn.FacetGrid.map
> 译者:[sfw134](https://github.com/sfw134)
```py
FacetGrid.map(func, *args, **kwargs)
```
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 &lt;cite&gt;color&lt;/cite&gt; keyword argument. If faceting on the &lt;cite&gt;hue&lt;/cite&gt; dimension, it must also take a &lt;cite&gt;label&lt;/cite&gt; keyword argument.
> 一个接受数据和关键字参数的绘图函数。它必须绘制到当前活动的matplotlib轴并采用&lt;cite&gt;color&lt;/cite&gt;关键字参数。如果在&lt;cite&gt;hue&lt;/cite&gt;维度上进行分面,必须也使用&lt;cite&gt;label&lt;/cite&gt;关键字参数。
`args`strings
`args`字符串
> Column names in self.data that identify variables with data to plot. The data for each variable is passed to &lt;cite&gt;func&lt;/cite&gt; in the order the variables are specified in the call.
> 数据的列名,用于标识要绘制数据的变量。每个变量的数据按照调用中指定变量的顺序传递给&lt;cite&gt;func&lt;/cite&gt;。
`kwargs`keyword arguments
`kwargs`关键字参数
> All keyword arguments are passed to the plotting function.
> 所有的关键字参数都被传递给绘图函数。
返回值:`self`object
返回值:`self`对象
> Returns self.
> 返回自身。
# seaborn.FacetGrid.map_dataframe
> 译者:[sfw134](https://github.com/sfw134)
```py
FacetGrid.map_dataframe(func, *args, **kwargs)
```
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 &lt;cite&gt;data&lt;/cite&gt; keyword argument and access the data in that DataFrame using string variable names.
此方法适用于使用接受长格式DataFrame作为&lt;cite&gt;data&lt;/cite&gt;关键字参数并使用字符串变量名访问该DataFrame中的数据的函数进行绘图。
参数:`func`callable
参数:`func`可调用
> A plotting function that takes data and keyword arguments. Unlike the &lt;cite&gt;map&lt;/cite&gt; method, a function used here must “understand” Pandas objects. It also must plot to the currently active matplotlib Axes and take a &lt;cite&gt;color&lt;/cite&gt; keyword argument. If faceting on the &lt;cite&gt;hue&lt;/cite&gt; dimension, it must also take a &lt;cite&gt;label&lt;/cite&gt; keyword argument.
> 一个接受数据和关键字参数的绘图函数。与&lt;cite&gt;map&lt;/cite&gt;方法不同,此处使用的函数必须“理解”Pandas对象。它也必须绘制到当前活动的matpltolib轴并采用&lt;cite&gt;color&lt;/cite&gt;关键字参数。如果在<cite>hue</cite>维度上进行分面,必须也使用<cite>label</cite>关键字参数。
`args`strings
`args`字符串
> Column names in self.data that identify variables with data to plot. The data for each variable is passed to &lt;cite&gt;func&lt;/cite&gt; in the order the variables are specified in the call.
> 数据的列名,用于标识要绘制数据的变量。每个变量的数据按照调用中指定变量的顺序传递给<cite>func</cite>。
`kwargs`keyword arguments
`kwargs`关键字参数
> All keyword arguments are passed to the plotting function.
> 所有的关键字参数被传递给绘图函数。
返回值:`self`object
返回值:`self`对象
> Returns self.
> 返回自身。
......@@ -4,73 +4,73 @@
class seaborn.PairGrid(data, hue=None, hue_order=None, palette=None, hue_kws=None, vars=None, x_vars=None, y_vars=None, diag_sharey=True, height=2.5, aspect=1, despine=True, dropna=True, size=None)
```
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.
它还可以通过`hue`参数用不同颜色绘制不同的数据子集来表示附加级别的条件化。这使用颜色来解析第三维的元素,但只是在彼此之上绘制子集,并且不会像接受`hue`的轴级函数那样为特定可视化定制`hue`参数。
See the [tutorial](../tutorial/axis_grids.html#grid-tutorial) for more information.
参考[教程](../tutorial/axis_grids.html#grid-tutorial)获取更多信息。
```py
__init__(data, hue=None, hue_order=None, palette=None, hue_kws=None, vars=None, x_vars=None, y_vars=None, diag_sharey=True, height=2.5, aspect=1, despine=True, dropna=True, size=None)
```
Initialize the plot figure and PairGrid object.
初始化绘图和PairGrid对象。
参数:`data`:DataFrame
参数:`data`:DataFrame格式
> 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 -&gt; list of values mapping
`hue_kws`参数字典 -&gt; 值列表映射
> 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).
> 其它的关键字参数,通过插入到绘图调用中使得其它的绘图属性在色调变量的不同水平上变化(例如散点图中的标记)。
`vars`list of variable names, optional
`vars`变量名列表, 可选
> Variables within `data` to use, otherwise use every column with a numeric datatype.
> 使用`data`中的变量,否则使用一个数值型数据类型的每一列。
`{x, y}_vars`lists of variable names, optional
`{x, y}_vars`变量名列表,可选
> Variables within `data` to use separately for the rows and columns of the figure; i.e. to make a non-square plot.
> 将`data`中的变量分别用于图的行和列,即制作非方形图。
`height`scalar, optional
`height`标量,可选
> Height (in inches) of each facet.
> 每个刻面的高度(以英寸为单位)。
`aspect`scalar, optional
`aspect`标量,可选
> Aspect * height gives the width (in inches) of each facet.
> aspect和height的乘积得出每个刻面的宽度(以英寸为单位)。
`despine`boolean, optional
`despine`布尔值,可选
> Remove the top and right spines from the plots.
> 从图中移除顶部和右侧脊柱。
`dropna`boolean, optional
`dropna`布尔值,可选
> Drop missing values from the data before plotting.
> 在绘图之前删除数据中的缺失值。
See also
另见
Easily drawing common uses of [`PairGrid`](#seaborn.PairGrid "seaborn.PairGrid").Subplot grid for plotting conditional relationships.
轻松绘制[`PairGrid`](#seaborn.PairGrid "seaborn.PairGrid")的常用用法。用于绘制条件关系的子图网格。
Examples
例子
Draw a scatterplot for each pairwise relationship:
为每个成对关系绘制一个散点图:
```py
>>> import matplotlib.pyplot as plt
......@@ -83,7 +83,7 @@ Draw a scatterplot for each pairwise relationship:
![http://seaborn.pydata.org/_images/seaborn-PairGrid-1.png](img/34fc6de3cfc117757cc0e5f658a06928.jpg)
Show a univariate distribution on the diagonal:
在对角线上显示单变量分布:
```py
>>> g = sns.PairGrid(iris)
......@@ -94,9 +94,9 @@ Show a univariate distribution on the diagonal:
![http://seaborn.pydata.org/_images/seaborn-PairGrid-2.png](img/7e2b84efc57efecba1f8c1bfad570874.jpg)
(It’s not actually necessary to catch the return value every time, as it is the same object, but it makes it easier to deal with the doctests).
(实际上没有必要每次都获取返回值,因为它是同一个对象,但它使得更容易处理文档测试)。
Color the points using a categorical variable:
使用分类变量对点进行着色:
```py
>>> g = sns.PairGrid(iris, hue="species")
......@@ -108,7 +108,7 @@ Color the points using a categorical variable:
![http://seaborn.pydata.org/_images/seaborn-PairGrid-3.png](img/6df84055fcde05fec3e0b9794967ad71.jpg)
Use a different style to show multiple histograms:
使用不同的样式显示多个直方图:
```py
>>> g = sns.PairGrid(iris, hue="species")
......@@ -120,7 +120,7 @@ Use a different style to show multiple histograms:
![http://seaborn.pydata.org/_images/seaborn-PairGrid-4.png](img/b269cdc188b02e86196c919d1bd87402.jpg)
Plot a subset of variables
绘制变量的子集
```py
>>> g = sns.PairGrid(iris, vars=["sepal_length", "sepal_width"])
......@@ -130,7 +130,7 @@ Plot a subset of variables
![http://seaborn.pydata.org/_images/seaborn-PairGrid-5.png](img/81ab9afd2faa6448de3c2b5a73ea3320.jpg)
Pass additional keyword arguments to the functions
将其它关键字参数传给函数。
```py
>>> g = sns.PairGrid(iris)
......@@ -141,7 +141,7 @@ Pass additional keyword arguments to the functions
![http://seaborn.pydata.org/_images/seaborn-PairGrid-6.png](img/ff58dc3588f11a9e3f9291926a0c86ff.jpg)
Use different variables for the rows and columns:
对行和列使用不同的变量:
```py
>>> g = sns.PairGrid(iris,
......@@ -153,7 +153,7 @@ Use different variables for the rows and columns:
![http://seaborn.pydata.org/_images/seaborn-PairGrid-7.png](img/0d8364e9bb731fa5d89b998087ba0635.jpg)
Use different functions on the upper and lower triangles:
在上三角和下三角使用不同的函数:
```py
>>> g = sns.PairGrid(iris)
......@@ -165,7 +165,7 @@ Use different functions on the upper and lower triangles:
![http://seaborn.pydata.org/_images/seaborn-PairGrid-8.png](img/58e8af844e6f097dc5995d7a2be70b0e.jpg)
Use different colors and markers for each categorical level:
为每个分类级别使用不同的颜色和标记:
```py
>>> g = sns.PairGrid(iris, hue="species", palette="Set2",
......@@ -177,14 +177,14 @@ Use different colors and markers for each categorical level:
![http://seaborn.pydata.org/_images/seaborn-PairGrid-9.png](img/c9a2068151affcefc99a7b280ab0a52b.jpg)
Methods
| [`__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. |
\ No newline at end of file
方法
| [`__init__`](#seaborn.PairGrid.__init__ "seaborn.PairGrid.__init__")(data[, hue, hue_order, palette, …]) | 初始化绘图和PairGrid对象。 |
| `add_legend`([legend_data, title, label_order]) | 绘制一个图例,可能将其放在轴外并调整图形大小。 |
| [`map`](seaborn.PairGrid.map.html#seaborn.PairGrid.map "seaborn.PairGrid.map")(func, **kwargs) | 在每一个子图上用相同的函数绘制。 |
| [`map_diag`](seaborn.PairGrid.map_diag.html#seaborn.PairGrid.map_diag "seaborn.PairGrid.map_diag")(func, **kwargs) | 在每个对角线子图上用一个单变量函数绘制。 |
| [`map_lower`](seaborn.PairGrid.map_lower.html#seaborn.PairGrid.map_lower "seaborn.PairGrid.map_lower")(func, **kwargs) | 在下三角子图上用一个双变量函数绘制。|
| [`map_offdiag`](seaborn.PairGrid.map_offdiag.html#seaborn.PairGrid.map_offdiag "seaborn.PairGrid.map_offdiag")(func, **kwargs) | 在非对角线子图上用一个双变量函数绘制。 |
| [`map_upper`](seaborn.PairGrid.map_upper.html#seaborn.PairGrid.map_upper "seaborn.PairGrid.map_upper")(func, **kwargs) | 在上三角子图上用一个双变量函数绘制。|
| `savefig`(*args, **kwargs) | 保存图。 |
| `set`(**kwargs) | 在每个子图轴上设置属性。 |
......@@ -4,9 +4,9 @@
PairGrid.map(func, **kwargs)
```
Plot with the same function in every subplot.
在每个子图中用相同的函数绘制。
参数:`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`.
> 必须将x,y数组作为位置参数并绘制到“当前活动”的matplotlib轴上。还需要接受名为`color`和`label`的kwargs。
......@@ -4,9 +4,9 @@
PairGrid.map_diag(func, **kwargs)
```
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`.
>必须将x,y数组作为位置参数并绘制到“当前活动”的matplotlib轴上。还需要接受名为color和label的kwargs。
......@@ -4,9 +4,9 @@
PairGrid.map_offdiag(func, **kwargs)
```
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`.
> 必须将x,y数组作为位置参数并绘制到“当前活动”的matplotlib轴上。还需要接受名为color和label的kwargs。
......@@ -4,9 +4,9 @@
PairGrid.map_lower(func, **kwargs)
```
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`.
> 必须将x,y数组作为位置参数并绘制到“当前活动”的matplotlib轴上。还需要接受名为`color`和`label`的kwargs。
# 可视化分类数据
> 译者:[hold2010](https://github.com/hold2010)
[绘制关系图](relational.html#relational-tutorial)的教程中,我们学习了如何使用不同的可视化方法来展示数据集中多个变量之间的关系。在示例中,我们专注于两个数值变量之间的主要关系。如果其中一个主要变量是“可分类的”(能被分为不同的组),那么我们可以使用更专业的可视化方法。
在seaborn中,有几种不同的方法可以对分类数据进行可视化。类似于[`relplot()`](../generated/seaborn.relplot.html#seaborn.relplot "seaborn.relplot")[`scatterplot()`](../generated/seaborn.scatterplot.html#seaborn.scatterplot "seaborn.scatterplot")或者[`lineplot()`](../generated/seaborn.lineplot.html#seaborn.lineplot "seaborn.lineplot")之间的关系,有两种方法可以制作这些图。有许多axes-level函数可以用不同的方式绘制分类数据,还有一个figure-level接口[`catplot()`](../generated/seaborn.catplot.html#seaborn.catplot "seaborn.catplot"),可以对它们进行统一的高级访问。
......
......@@ -4,9 +4,9 @@
PairGrid.map_upper(func, **kwargs)
```
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`.
> 必须将x,y数组作为位置参数并绘制到“当前活动”的matplotlib轴上。还需要接受名为color和label的kwargs。
......@@ -4,51 +4,49 @@
class seaborn.JointGrid(x, y, data=None, height=6, ratio=5, space=0.2, dropna=True, xlim=None, ylim=None, size=None)
```
Grid for drawing a bivariate plot with marginal univariate plots.
用于绘制具有边际单变量图的双变量图的网格。
```py
__init__(x, y, data=None, height=6, ratio=5, space=0.2, dropna=True, xlim=None, ylim=None, size=None)
```
Set up the grid of subplots.
设置子图的网格。
参数:`x, y`strings or vectors
参数:`x, y`字符串或向量
> Data or names of variables in `data`.
> 在 `data`中的数据或变量名
`data`:DataFrame, optional
`data`:DataFrame, 可选
> DataFrame when `x` and `y` are variable names.
> 当 `x` and `y` 是变量名的时候为DataFrame。
`height`numeric
`height`数字
> Size of each side of the figure in inches (it will be square).
> 图中每一条边的大小(以英寸为单位)
`ratio`numeric
`ratio`数字
> Ratio of joint axes size to marginal axes height.
> 联合轴大小与边缘轴高度的比率。
`space`numeric, optional
`space`数字,可选
> Space between the joint and marginal axes
> 联合轴和边缘轴之间的空间
`dropna`:bool, optional
`dropna`:bool, 可选
> If True, remove observations that are missing from &lt;cite&gt;x&lt;/cite&gt; and &lt;cite&gt;y&lt;/cite&gt;.
> 如果为True,则删除 &lt;cite&gt;x&lt;/cite&gt; 和 &lt;cite&gt;y&lt;/cite&gt;中缺少的观察结果。
`{x, y}lim`two-tuples, optional
`{x, y}lim`二元组,可选
> Axis limits to set before plotting.
> 在绘图之前设置轴限制。
也可以看看
用于绘制具有多种不同默认绘图类型的双变量图的高级界面。
See also
例子:
High-level interface for drawing bivariate plots with several different default plot kinds.
Examples
Initialize the figure but don’t draw any plots onto it:
初始化图形,但不在其上绘制任何图形:
```py
>>> import seaborn as sns; sns.set(style="ticks", color_codes=True)
......@@ -59,7 +57,7 @@ Initialize the figure but don’t draw any plots onto it:
![http://seaborn.pydata.org/_images/seaborn-JointGrid-1.png](img/a0e79dac9add2a97da1c95241a6122ab.jpg)
Add plots using default parameters:
使用默认参数添加绘图:
```py
>>> g = sns.JointGrid(x="total_bill", y="tip", data=tips)
......@@ -69,7 +67,7 @@ Add plots using default parameters:
![http://seaborn.pydata.org/_images/seaborn-JointGrid-2.png](img/f984c858bd63441ea9761d632cb76d2c.jpg)
Draw the join and marginal plots separately, which allows finer-level control other parameters:
分别绘制联合分布图和边缘直方图,这可以以更精细的级别控制其他参数:
```py
>>> import matplotlib.pyplot as plt
......@@ -81,7 +79,7 @@ Draw the join and marginal plots separately, which allows finer-level control ot
![http://seaborn.pydata.org/_images/seaborn-JointGrid-3.png](img/3e159b4a38edb79ede76d93a55e2acb9.jpg)
Draw the two marginal plots separately:
分别绘制两个边缘直方图:
```py
>>> import numpy as np
......@@ -97,7 +95,7 @@ Draw the two marginal plots separately:
![http://seaborn.pydata.org/_images/seaborn-JointGrid-4.png](img/1db698012d05626321ac93ffb7668a2c.jpg)
Add an annotation with a statistic summarizing the bivariate relationship:
添加注释,其中包含总结双变量关系的统计信息:
```py
>>> from scipy import stats
......@@ -111,7 +109,7 @@ Add an annotation with a statistic summarizing the bivariate relationship:
![http://seaborn.pydata.org/_images/seaborn-JointGrid-5.png](img/fa99a0a13450712a4f2b13d983b1e766.jpg)
Use a custom function and formatting for the annotation
使用自定义的函数和注释格式
```py
>>> g = sns.JointGrid(x="total_bill", y="tip", data=tips)
......@@ -126,7 +124,7 @@ Use a custom function and formatting for the annotation
![http://seaborn.pydata.org/_images/seaborn-JointGrid-6.png](img/a8307f7ba7809b63c523168fde9e9379.jpg)
Remove the space between the joint and marginal axes:
移除联合轴和边缘轴之间的空间:
```py
>>> g = sns.JointGrid(x="total_bill", y="tip", data=tips, space=0)
......@@ -137,7 +135,7 @@ Remove the space between the joint and marginal axes:
![http://seaborn.pydata.org/_images/seaborn-JointGrid-7.png](img/5beaabfceb79e2eef9563fc3044dd5f6.jpg)
Draw a smaller plot with relatively larger marginal axes:
绘制具有相对较大边缘轴的较小图:
```py
>>> g = sns.JointGrid(x="total_bill", y="tip", data=tips,
......@@ -149,7 +147,7 @@ Draw a smaller plot with relatively larger marginal axes:
![http://seaborn.pydata.org/_images/seaborn-JointGrid-8.png](img/bfc4c60af4e09992569375d51943de88.jpg)
Set limits on the axes:
设置轴的限制:
```py
>>> g = sns.JointGrid(x="total_bill", y="tip", data=tips,
......@@ -161,12 +159,18 @@ Set limits on the axes:
![http://seaborn.pydata.org/_images/seaborn-JointGrid-9.png](img/3a85305cd59104b4d9403deb570373cc.jpg)
Methods
方法
[`__init__`](#seaborn.JointGrid.__init__ "seaborn.JointGrid.__init__")(x, y[, data, height, ratio, space, …]) | 设置子图的网格设置子图的网格。
`annotate`(func[, template, stat, loc]) | 用关于关系的统计数据来标注绘图。
[`plot`](seaborn.JointGrid.plot.html#seaborn.JointGrid.plot "seaborn.JointGrid.plot")(joint_func, marginal_func[, annot_func]) | 绘制完整绘图的快捷方式。
[`plot_joint`](seaborn.JointGrid.plot_joint.html#seaborn.JointGrid.plot_joint "seaborn.JointGrid.plot_joint")(func, **kwargs) | 绘制 &lt;cite&gt;x&lt;/cite&gt;&lt;cite&gt;y&lt;/cite&gt;的双变量图。
[`plot_marginals`](seaborn.JointGrid.plot_marginals.html#seaborn.JointGrid.plot_marginals "seaborn.JointGrid.plot_marginals")(func, **kwargs) | 分别绘制 &lt;cite&gt;x&lt;/cite&gt;&lt;cite&gt;y&lt;/cite&gt; 的单变量图。
`savefig`(*args, **kwargs) | 封装 figure.savefig 默认为紧边界框。
| [`__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 &lt;cite&gt;x&lt;/cite&gt; and &lt;cite&gt;y&lt;/cite&gt;. |
| [`plot_marginals`](seaborn.JointGrid.plot_marginals.html#seaborn.JointGrid.plot_marginals "seaborn.JointGrid.plot_marginals")(func, **kwargs) | Draw univariate plots for &lt;cite&gt;x&lt;/cite&gt; and &lt;cite&gt;y&lt;/cite&gt; separately. |
| `savefig`(*args, **kwargs) | Wrap figure.savefig defaulting to tight bounding box. |
| `set_axis_labels`([xlabel, ylabel]) | Set the axis labels on the bivariate axes. |
\ No newline at end of file
`set_axis_labels`([xlabel, ylabel]) |在双变量轴上设置轴标签。
......@@ -4,16 +4,14 @@
JointGrid.plot(joint_func, marginal_func, annot_func=None)
```
Shortcut to draw the full plot.
绘制完整绘图的快捷方式。
Use &lt;cite&gt;plot_joint&lt;/cite&gt; and &lt;cite&gt;plot_marginals&lt;/cite&gt; directly for more control.
直接使用 &lt;cite&gt;plot_joint&lt;/cite&gt;&lt;cite&gt;plot_marginals&lt;/cite&gt; 进行更多控制.
参数:**joint_func, marginal_func:callables**
参数:**joint_func, marginal_func:可调用**
> Functions to draw the bivariate and univariate plots.
> 绘制双变量和单变量图的函数。
返回值:`self`:JointGrid 实例
返回值:`self`:JointGrid instance
> Returns &lt;cite&gt;self&lt;/cite&gt;.
> 返回 &lt;cite&gt;self&lt;/cite&gt;.
......@@ -4,18 +4,16 @@
JointGrid.plot_joint(func, **kwargs)
```
Draw a bivariate plot of &lt;cite&gt;x&lt;/cite&gt; and &lt;cite&gt;y&lt;/cite&gt;.
绘制 &lt;cite&gt;x&lt;/cite&gt; and &lt;cite&gt;y&lt;/cite&gt;的双变量图。
参数:`func`plotting callable
参数:`func`可调用的绘图函数
> This must take two 1d arrays of data as the first two positional arguments, and it must plot on the “current” axes.
> 这必须将两个一维数据数组作为前两个位置参数,并且必须在“当前”轴上绘制。
`kwargs`key, value mappings
`kwargs`键,值映射
> Keyword argument are passed to the plotting function.
> 关键字参数传递给绘图函数。
返回值:`self`:JointGrid 实例
返回值:`self`:JointGrid instance
> Returns &lt;cite&gt;self&lt;/cite&gt;.
> 返回 &lt;cite&gt;self&lt;/cite&gt;.
......@@ -4,18 +4,16 @@
JointGrid.plot_marginals(func, **kwargs)
```
Draw univariate plots for &lt;cite&gt;x&lt;/cite&gt; and &lt;cite&gt;y&lt;/cite&gt; separately.
分别绘制 &lt;cite&gt;x&lt;/cite&gt;&lt;cite&gt;y&lt;/cite&gt; 的单变量图。
参数:`func`plotting callable
参数:`func`可调用的绘图函数
> 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.
> 这必须将一维数据数组作为第一个位置参数,它必须在“当前”轴上绘图,并且它必须接受“垂直”关键字参数以垂直定向图的度量维度。
`kwargs`key, value mappings
`kwargs`键,值映射
> Keyword argument are passed to the plotting function.
> 关键字参数传递给绘图函数。
返回值:`self`:JointGrid 实例
返回值:`self`:JointGrid instance
> Returns &lt;cite&gt;self&lt;/cite&gt;.
> 返回 &lt;cite&gt;self&lt;/cite&gt;.
# seaborn.set
```py
```python
seaborn.set(context='notebook', style='darkgrid', palette='deep', font='sans-serif', font_scale=1, color_codes=True, rc=None)
```
Set aesthetic parameters in one step.
一步设定自定义图表参数。
Each set of parameters can be set directly or temporarily, see the referenced functions below for more information.
每个参数可以被直接或者间接设定,参见下方的引用参数以获取更多信息。
参数:`context`:string or dict
参数:context:字符串或者字典
> Plotting context parameters, see [`plotting_context()`](seaborn.plotting_context.html#seaborn.plotting_context "seaborn.plotting_context")
> 绘图上下文参数,参见[`plotting_context()`](https://github.com/apachecn/seaborn-doc-zh/blob/master/docs/seaborn.plotting_context.html#seaborn.plotting_context)
`style`:string or dict
style:字符串或者字典
> Axes style parameters, see [`axes_style()`](seaborn.axes_style.html#seaborn.axes_style "seaborn.axes_style")
> 坐标轴样式参数,参见[`axes_style()`](https://github.com/apachecn/seaborn-doc-zh/blob/master/docs/seaborn.axes_style.html#seaborn.axes_style)
`palette`:string or sequence
palette:字符串或者序列
> Color palette, see [`color_palette()`](seaborn.color_palette.html#seaborn.color_palette "seaborn.color_palette")
> 调色板,参见[`color_palette()`](https://github.com/apachecn/seaborn-doc-zh/blob/master/docs/seaborn.color_palette.html#seaborn.color_palette)
`font`:string
font:字符串
> Font family, see matplotlib font manager.
> 字体,参见matplotlib字体管理
`font_scale`:float, optional
font_scale:浮点数,可选的
> Separate scaling factor to independently scale the size of the font elements.
> 独立缩放因子,以独立缩放字体元素的大小。
`color_codes`:bool
color_codes:布尔值
> If `True` and `palette` is a seaborn palette, remap the shorthand color codes (e.g. “b”, “g”, “r”, etc.) to the colors from this palette.
> 如果为真并且调色板是一个seaborn调色板,重新映射速记颜色代码(比如,"b","g","r",等等)到调色板上的颜色。
`rc`:dict or None
> Dictionary of rc parameter mappings to override the above.
rc:字典或者None
> rc参数字典映射以覆盖以上参数。
\ No newline at end of file
# seaborn.axes_style
```py
seaborn.axes_style(style=None, rc=None)
```python
seaborn.axes_style(style=None,rc=None)
```
Return a parameter dict for the aesthetic style of the plots.
返回一个参数数组作为图表的自定义风格。
This affects things like the color of the axes, whether a grid is enabled by default, and other aesthetic elements.
它会影响诸如坐标轴的颜色,是否默认启用网格,和其他自定义元素。
This function returns an object that can be used in a `with` statement to temporarily change the style parameters.
这个函数返回一个对象,该对象可以在with语句中使用以临时改变样式参数。
参数:`style`:dict, None, or one of {darkgrid, whitegrid, dark, white, ticks}
参数:style:字典,None,或者{darkgrid, whitegrid, dark, white, ticks}其中一个。
> 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.
> 给定参数映射以覆盖预先设定的(默认的)seaborn样式参数字典
参见
给一个seaborn主题设定matplotlib参数,返回一个参数字典,以缩放图标元素并可以定义图表的调色板。
See also
例子:
set the matplotlib parameters for a seaborn themereturn a parameter dict to to scale plot elementsdefine the color palette for a plot
Examples
```py
```python
>>> st = axes_style("whitegrid")
```
```py
```python
>>> set_style("ticks", {"xtick.major.size": 8, "ytick.major.size": 8})
```
```py
```python
>>> import matplotlib.pyplot as plt
>>> with axes_style("white"):
... f, ax = plt.subplots()
... ax.plot(x, y)
... ax.plot(x, y)
```
```
\ No newline at end of file
# seaborn.set_style
```py
```python
seaborn.set_style(style=None, rc=None)
```
Set the aesthetic style of the plots.
设定图表的自定义风格。
This affects things like the color of the axes, whether a grid is enabled by default, and other aesthetic elements.
它会影响诸如坐标轴的颜色,网格默认是否开启和其他自定义元素。
参数:`style`:dict, None, or one of {darkgrid, whitegrid, dark, white, ticks}
参数:style:字典,None,或者{darkgrid, whitegrid, dark, white, ticks}其中一个。
> 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.
> 一个字典映射去覆盖seaborn样式字典中的预设值。这仅仅会更新那些被认为是样式定义一部分的参数。
参见
返回一个参数字典或者使用with语句以临时设置style.set 的参数来缩放图表的元素或者设定图表的默认调色板。
See also
例子:
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
Examples
```py
```python
>>> set_style("whitegrid")
```
```py
```python
>>> set_style("ticks", {"xtick.major.size": 8, "ytick.major.size": 8})
```
```
\ No newline at end of file
# seaborn.plotting_context
```py
```python
seaborn.plotting_context(context=None, font_scale=1, rc=None)
```
以dict形式返回参数,用以缩放图形的元素。
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}
这些参数可以影响诸如标签大小,线条和绘图的其他元素,但不会影响整体样式。基础文本时"notebook",和其他文本"paper","talk"和"poster",它们分别是0.8,1.3和1.6的notebook参数版本。
> A dictionary of parameters or the name of a preconfigured set.
该函数返回一个对象,该对象可以在`with`语句中使用,临时改变文本参数。
`font_scale`:float, optional
参数:`context`:dict, None 或者是{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
设置matplotlib参数以调整绘图元素返回定义图形样式的参数的dict,定义绘图的调色板。
Examples
示例:
```py
```python
>>> c = plotting_context("poster")
```
```py
```python
>>> c = plotting_context("notebook", font_scale=1.5)
```
```py
```python
>>> c = plotting_context("talk", rc={"lines.linewidth": 2})
```
```py
```python
>>> import matplotlib.pyplot as plt
>>> with plotting_context("paper"):
... f, ax = plt.subplots()
... ax.plot(x, y)
... f, ax = plt.subplots()
... ax.plot(x, y)
```
```
\ No newline at end of file
# seaborn.set_context
```py
seaborn.set_context(context=None, font_scale=1, rc=None)
```
Set the plotting context parameters.
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
Examples
```py
>>> set_context("paper")
```
```py
>>> set_context("talk", font_scale=1.4)
```
```py
>>> set_context("talk", rc={"lines.linewidth": 2})
```
\ No newline at end of file
# seaborn.set_context
```python
seaborn.set_context(context=None, font_scale=1, rc=None)
```
设置绘图文本参数。
这些参数可以影响诸如标签大小,线条和绘图的其他元素,但不会影响整体样式。基础文本时"notebook",和其他文本"paper","talk"和"poster",它们分别是0.8,1.3和1.6的notebook参数版本。
参数:`context`:dict, None 或者是{paper, notebook, talk, poster}其中一个
> 参数集或者是预设集合的名字
`font_scale`:浮点数,可选
> 单独的缩放因子可以独立缩放字体元素大小
`rc`:dict,可选
> 参数映射以覆盖预设的seaborn的上下文字典中的值。这只更新被视为上下文定义的一部分的参数。
也可参见
返回一个rc参数的字典,或者在`with`语句中使用临时设置context.set图样式的默认为数字的默认调色板
示例
```python
>>> set_context("paper")
```
```python
>>> set_context("talk", font_scale=1.4)
```
```python
>>> set_context("talk", rc={"lines.linewidth": 2})
```
# seaborn.set_color_codes
```py
seaborn.set_color_codes(palette='deep')
```
Change how matplotlib color shorthands are interpreted.
Calling this will change how shorthand codes like “b” or “g” are interpreted by matplotlib in subsequent plots.
参数:`palette`:{deep, muted, pastel, dark, bright, colorblind}
> 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.
```py
>>> import matplotlib.pyplot as plt
>>> import seaborn as sns; sns.set()
>>> sns.set_color_codes()
>>> _ = plt.plot([0, 1], color="r")
```
![http://seaborn.pydata.org/_images/seaborn-set_color_codes-1.png](img/f7331a33eaedf9eae59191642f7a64e4.jpg)
Use a different seaborn palette.
```py
>>> sns.set_color_codes("dark")
>>> _ = plt.plot([0, 1], color="g")
>>> _ = plt.plot([0, 2], color="m")
```
![http://seaborn.pydata.org/_images/seaborn-set_color_codes-2.png](img/35544ecf6de962c91ab860527035f39f.jpg)
\ No newline at end of file
# seaborn.set_color_codes
```python
seaborn.set_color_codes(palette='deep')
```
改变matplotlib颜色缩写词的解释方式。
调用此方法将改变matplotlib在后续图表中解释缩写词,例如"b"或"g"的方式。
参数: `palette`: {deep, muted, pastel, dark, bright, colorblind}
> 预命名的seaborn调色板,用作颜色的来源
参见
可以通过高级seaborn样式管理器设置颜色代码。也可以通过设置matplotlib颜色循环功能设置颜色代码。
示例:
将matplotlib颜色代码映射到默认的seaborn调色板。
```python
>>> import matplotlib.pyplot as plt
>>> import seaborn as sns; sns.set()
>>> sns.set_color_codes()
>>> _ = plt.plot([0, 1], color="r")
```
![http://seaborn.pydata.org/_images/seaborn-set_color_codes-1.png](img/f7331a33eaedf9eae59191642f7a64e4.jpg)
使用不同的seaborn调色板
```python
>>> sns.set_color_codes("dark")
>>> _ = plt.plot([0, 1], color="g")
>>> _ = plt.plot([0, 2], color="m")
```
![http://seaborn.pydata.org/_images/seaborn-set_color_codes-2.png](img/35544ecf6de962c91ab860527035f39f.jpg)
# seaborn.reset_defaults
```py
seaborn.reset_defaults()
```
Restore all RC params to default settings.
\ No newline at end of file
# seaborn.reset_defaults
```python
seaborn.reset_defaults()
```
重置所有RC设置至默认设置。
\ No newline at end of file
# seaborn.reset_orig
```py
seaborn.reset_orig()
```
Restore all RC params to original settings (respects custom rc).
\ No newline at end of file
# seaborn.reset_orig
```python
seaborn.reset_orig()
```
将所有RC参数恢复为最初设置(相对于自定义rc而言)。
此差异已折叠。
# Controlling figure aesthetics
# 控制图像的美学样式(aesthetics)
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.
绘制有吸引力的图像很十分重要的。当你在探索一个数据集并为你自己做图的时候,制作一些让人看了心情愉悦的图像是很好的。可视化对向观众传达量化的简介也是很重要的,在这种情况下制作能够抓住查看者的注意力并牢牢吸引住他们的图像就更有必要了。
Matplotlib是高度可定制的,但是很难知道要如何设置图像才能使得图像更加吸引人。Seaborn提供了许多定制好的主题和高级的接口,用于控制Matplotlib所做图像的外观。
```py
import numpy as np
......@@ -11,7 +13,7 @@ import matplotlib.pyplot as plt
```
Let’s define a simple function to plot some offset sine waves, which will help us see the different stylistic parameters we can tweak.
让我们定义一个简单的函数来绘制一些偏移正弦波,这将帮助我们看到我们可以调整的能够影响图像风格的不同参数。
```py
def sinplot(flip=1):
......@@ -21,7 +23,7 @@ def sinplot(flip=1):
```
This is what the plot looks like with matplotlib defaults:
这是Matplotlib默认情况下的绘图外观:
```py
sinplot()
......@@ -30,7 +32,7 @@ sinplot()
![http://seaborn.pydata.org/_images/aesthetics_7_0.png](img/4784d932a8738cea5085be56ce6f7315.jpg)
To switch to seaborn defaults, simply call the [`set()`](../generated/seaborn.set.html#seaborn.set "seaborn.set") function.
为了将图像的风格转变为seaborn的默认样式,我们可以 [`set()`](../generated/seaborn.set.html#seaborn.set "seaborn.set") 函数。
```py
sns.set()
......@@ -40,15 +42,15 @@ sinplot()
![http://seaborn.pydata.org/_images/aesthetics_9_0.png](img/2422a0c0d2c96ec6397babaa6c842d79.jpg)
(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).
(注意,在0.8之前的seaborn版本中, [`set()`](../generated/seaborn.set.html#seaborn.set "seaborn.set") 已经在使用impory语句导入的时候就被调用了。但在以后的版本中,必须要显式调用它)。
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.
Seaborn将matplotlib参数分成两个独立的组。第一组设置了图像的美术风格,第二组则对图像中不同的元素进行了控制,使得图像可以很容易地融入不同的环境中。
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.
操作这些参数的接口是两对函数。要控制样式,请使用 [`axes_style()`](../generated/seaborn.axes_style.html#seaborn.axes_style "seaborn.axes_style")[`set_style()`](../generated/seaborn.set_style.html#seaborn.set_style "seaborn.set_style") 函数。要对图像中元素的样式进行修改,请使用 [`plotting_context()`](../generated/seaborn.plotting_context.html#seaborn.plotting_context "seaborn.plotting_context")[`set_context()`](../generated/seaborn.set_context.html#seaborn.set_context "seaborn.set_context") 函数。在这两种情况下(控制图像样式与修改元素样式),第一个函数会返回一个参数字典,第二个函数设置matplotlib中相关参数的默认值。
## Seaborn figure styles
## Seaborn图像参数
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:
有五个预设的Seaborn主题: `darkgrid``whitegrid``dark``white`以及 `ticks`。它们分别适用于不同的应用程序和个人偏好。默认主题为 `darkgrid`。如上所述,坐标方格有助于将制出的图像用作定量信息的查阅表,灰色背景上的白色有助于防止网格与表示数据的行发生竞争。 `whitegrid` 主题类似,但它更适用于包含大量数据元素的绘图:
```py
sns.set_style("whitegrid")
......@@ -59,7 +61,7 @@ sns.boxplot(data=data);
![http://seaborn.pydata.org/_images/aesthetics_11_0.png](img/ba3b8a1ba98a18cbe9f37192b2338932.jpg)
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.
对许多的图像而言,(尤其是在你只是想通过图像来提供给人们一个对数据模式的印象时,比如说作报告时)坐标网格都是不必要的。
```py
sns.set_style("dark")
......@@ -77,7 +79,7 @@ sinplot()
![http://seaborn.pydata.org/_images/aesthetics_14_0.png](img/47decb21ce3a9413876a02f2967ef7aa.jpg)
Sometimes you might want to give a little extra structure to the plots, which is where ticks come in handy:
有时,您可能希望为绘图提供一点额外的结构,这正是tick样式的用武之地:
```py
sns.set_style("ticks")
......@@ -87,9 +89,9 @@ sinplot()
![http://seaborn.pydata.org/_images/aesthetics_16_0.png](img/d23eefa56e1ef945c75b43ab4fc651a4.jpg)
## Removing axes spines
## 移除坐标轴
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:
`white` 样式与 `ticks` 样式的好处是都能删除所不需要的顶部与右部坐标轴。使用seaborn中的函数 [`despine()`](../generated/seaborn.despine.html#seaborn.despine "seaborn.despine") 可以来移除它们:
```py
sinplot()
......@@ -99,7 +101,7 @@ sns.despine()
![http://seaborn.pydata.org/_images/aesthetics_18_0.png](img/b9a7a625477fd6d6c167844f557d14dd.jpg)
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.
有些图的好处在于,可以让坐标的主轴随着数据进行偏移,这可以使用 [`despine()`](../generated/seaborn.despine.html#seaborn.despine "seaborn.despine")函数来完成。当刻度无法覆盖轴的整个范围时,`trim`参数将限制不受影响的坐标轴的范围。
```py
f, ax = plt.subplots()
......@@ -110,7 +112,7 @@ sns.despine(offset=10, trim=True);
![http://seaborn.pydata.org/_images/aesthetics_20_0.png](img/7c21c8cb297826c3a45b483039151d9e.jpg)
You can also control which spines are removed with additional arguments to [`despine()`](../generated/seaborn.despine.html#seaborn.despine "seaborn.despine"):
你也可以通过控制 [`despine()`](../generated/seaborn.despine.html#seaborn.despine "seaborn.despine")的额外参数来删除坐标轴:
```py
sns.set_style("whitegrid")
......@@ -121,9 +123,9 @@ sns.despine(left=True)
![http://seaborn.pydata.org/_images/aesthetics_22_0.png](img/4f24815584c7c584945d529f3d9dbfbf.jpg)
## Temporarily setting figure style
## 设置临时图像格式
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:
虽然来回切换很容易,但你也可以在`with`语句中使用 [`axes_style()`](../generated/seaborn.axes_style.html#seaborn.axes_style "seaborn.axes_style") 函数来临时设置绘图参数。 这也允许您使用不同风格的坐标轴制作图形:
```py
f = plt.figure()
......@@ -137,11 +139,11 @@ sinplot(-1)
![http://seaborn.pydata.org/_images/aesthetics_24_0.png](img/1b8ec9b9fb72e9193bfefe933d976d37.jpg)
## Overriding elements of the seaborn styles
## 覆盖控制seaborn样式的元素
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).
如果你想要自己定制seaborn的样式,你可以通过给 [`axes_style()`](../generated/seaborn.axes_style.html#seaborn.axes_style "seaborn.axes_style")[`set_style()`](../generated/seaborn.set_style.html#seaborn.set_style "seaborn.set_style")函数中的 `rc` 参数传递一个参数字典来实现。请注意,您只能通过此方法覆盖作为样式定义一部分的参数。(但是,更高级别的 [`set()`](../generated/seaborn.set.html#seaborn.set "seaborn.set") 函数会获取任何matplotlib参数的字典)。
If you want to see what parameters are included, you can just call the function with no arguments, which will return the current settings:
如果你想看看包含哪些参数,你可以只调用没有参数的函数,这将返回当前设置:
```py
sns.axes_style()
......@@ -183,7 +185,7 @@ sns.axes_style()
```
You can then set different versions of these parameters:
然后,您可以设置这些参数的不同版本:
```py
sns.set_style("darkgrid", {"axes.facecolor": ".9"})
......@@ -193,18 +195,18 @@ sinplot()
![http://seaborn.pydata.org/_images/aesthetics_28_0.png](img/5ebb828c6eed309cb239f2219f35397c.jpg)
## Scaling plot elements
## 缩放图像元素
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"):
首先,让我们通过调用 [`set()`](../generated/seaborn.set.html#seaborn.set "seaborn.set")来重置默认的参数:
```py
sns.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.
按照相对大小的顺序排序,四个预设环境是 `paper``notebook``talk``poster``notebook`样式是默认样式,上文中的图就是使用该样式绘制的。
```py
sns.set_context("paper")
......@@ -230,11 +232,11 @@ sinplot()
![http://seaborn.pydata.org/_images/aesthetics_34_0.png](img/5788d7f7d4b9f29480e997849d16ee10.jpg)
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.
你可以通过在调用 [`set_context()`](../generated/seaborn.set_context.html#seaborn.set_context "seaborn.set_context") 时指定环境的名字来设置参数,你也可以通过提供一个参数字典来覆盖原有的参数值。
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).
你也在转换环境的时候独立地对字符元素的大小进行缩放。(这个操作也能够顶层的 [`set()`](../generated/seaborn.set.html#seaborn.set "seaborn.set") 函数来实现)。
```py
sns.set_context("notebook", font_scale=1.5, rc={"lines.linewidth": 2.5})
......@@ -244,6 +246,7 @@ sinplot()
![http://seaborn.pydata.org/_images/aesthetics_36_0.png](img/2b8879fda28a3be3acac977e15cbeebb.jpg)
Similarly, you can temporarily control the scale of figures nested under a `with` statement.
同样的,你也可以暂时的通过嵌套在 `with` 语句下的语句来实现图像的缩放。
样式和环境都可以使用 [`set()`](../generated/seaborn.set.html#seaborn.set "seaborn.set") 函数快速配置。 此函数还设置默认调色板,但更详细的介绍将在本教程的 [下一节](color_palettes.html#palette-tutorial) 进行叙述。
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.
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册