未验证 提交 00c8a4d6 编写于 作者: 飞龙 提交者: GitHub

Merge pull request #16 from hyuuo/master

24 25 30 32提交
# seaborn.distplot
# seaborn.distplot
```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)
```
Flexibly plot a univariate distribution of observations.
This function combines the matplotlib `hist` function (with automatic calculation of a good default bin size) with the seaborn [`kdeplot()`](seaborn.kdeplot.html#seaborn.kdeplot "seaborn.kdeplot") and [`rugplot()`](seaborn.rugplot.html#seaborn.rugplot "seaborn.rugplot") functions. It can also fit `scipy.stats` distributions and plot the estimated PDF over the data.
灵活绘制单变量观测值分布图。
参数:`a`:Series, 1d-array, or list.
该函数结合了matplotlib中的 `hist`函数(自动计算一个默认的合适的bin大小)、seaborn的[`kdeplot()`](seaborn.kdeplot.html#seaborn.kdeplot "seaborn.kdeplot")[`rugplot()`](seaborn.rugplot.html#seaborn.rugplot "seaborn.rugplot")函数。它还可以拟合`scipy.stats`分布并在数据上绘制估计的PDF(概率分布函数)。
> Observed data. If this is a Series object with a `name` attribute, the name will be used to label the data axis.
参数:`a`:Series、1维数组或者列表。
`bins`:argument for matplotlib hist(), or None, optional
> 观察数据。如果是具有`name`属性的Series对象,则该名称将用于标记数据轴。
> Specification of hist bins, or None to use Freedman-Diaconis rule.
`bins`:matplotlib hist()的参数,或None。可选参数。
`hist`:bool, optional
> 直方图bins(柱)的数目,若填None,则默认使用Freedman-Diaconis规则指定柱的数目。
> Whether to plot a (normed) histogram.
`hist`:布尔值,可选参数。
`kde`:bool, optional
> 是否绘制(标准化)直方图。
> Whether to plot a gaussian kernel density estimate.
`kde`:布尔值,可选参数。
`rug`:bool, optional
> 是否绘制高斯核密度估计图。
> Whether to draw a rugplot on the support axis.
`rug`:布尔值,可选参数。
`fit`:random variable object, optional
> 是否在横轴上绘制观测值竖线。
> An object with <cite>fit</cite> method, returning a tuple that can be passed to a <cite>pdf</cite> method a positional arguments following an grid of values to evaluate the pdf on.
`fit`:随机变量对象,可选参数。
`{hist, kde, rug, fit}_kws`:dictionaries, optional
> 一个带有*fit*方法的对象,返回一个元组,该元组可以传递给*pdf*方法一个位置参数,该位置参数遵循一个值的网格用于评估pdf。
> Keyword arguments for underlying plotting functions.
`{hist, kde, rug, fit}_kws`:字典,可选参数。
`color`:matplotlib color, optional
> 底层绘图函数的关键字参数。
> Color to plot everything but the fitted curve in.
`color`:matplotlib color,可选参数。
`vertical`:bool, optional
> 可以绘制除了拟合曲线之外所有内容的颜色。
> If True, observed values are on y-axis.
`vertical`:布尔值,可选参数。
`norm_hist`:bool, optional
> 如果为True,则观测值在y轴显示。
> If True, the histogram height shows a density rather than a count. This is implied if a KDE or fitted density is plotted.
`norm_hist`:布尔值,可选参数。
`axlabel`:string, False, or None, optional
> 如果为True,则直方图的高度显示密度而不是计数。如果绘制KDE图或拟合密度,则默认为True。
> Name for the support axis label. If None, will try to get it from a.namel if False, do not set a label.
`axlabel`:字符串,False或者None,可选参数。
`label`:string, optional
> 横轴的名称。如果为None,将尝试从a.name获取它;如果为False,则不设置标签。
> Legend label for the relevent component of the plot
`label`:字符串,可选参数。
`ax`:matplotlib axis, optional
> 图形相关组成部分的图例标签。
> if provided, plot on this axis
`ax`:matplotlib axis,可选参数。
> 若提供该参数,则在参数设定的轴上绘图。
返回值:`ax`:matplotlib Axes
> Returns the Axes object with the plot for further tweaking.
> 返回Axes对象以及用于进一步调整的绘图。
**另请参见**
[`kdeplot`](seaborn.kdeplot.html#seaborn.kdeplot "seaborn.kdeplot")
See also
显示具有核密度估计图的单变量或双变量分布。
Show a univariate or bivariate distribution with a kernel density estimate.Draw small vertical lines to show each observation in a distribution.
[`rugplot`](seaborn.rugplot.html#seaborn.rugplot "seaborn.rugplot")
Examples
绘制小的垂直线以显示分布中的每个观测值。
Show a default plot with a kernel density estimate and histogram with bin size determined automatically with a reference rule:
**范例**
显示具有核密度估计的默认图和使用参考规则自动确定bin大小的直方图:
```py
>>> import seaborn as sns, numpy as np
>>> sns.set(); np.random.seed(0)
......@@ -82,10 +83,9 @@ Show a default plot with a kernel density estimate and histogram with bin size d
>>> ax = sns.distplot(x)
```
![http://seaborn.pydata.org/_images/seaborn-distplot-1.png](img/dfbc2ec93ea21c479448cd2e25976945.jpg)
Use Pandas objects to get an informative axis label:
使用Pandas对象获取信息轴标签:
```py
>>> import pandas as pd
......@@ -96,7 +96,7 @@ Use Pandas objects to get an informative axis label:
![http://seaborn.pydata.org/_images/seaborn-distplot-2.png](img/d33f6bf00c0886595c68d970316b0717.jpg)
Plot the distribution with a kernel density estimate and rug plot:
使用核密度估计和小的垂直线绘制分布图:
```py
>>> ax = sns.distplot(x, rug=True, hist=False)
......@@ -105,7 +105,7 @@ Plot the distribution with a kernel density estimate and rug plot:
![http://seaborn.pydata.org/_images/seaborn-distplot-3.png](img/85548cb1190d0ad63fbaf33d0966b16d.jpg)
Plot the distribution with a histogram and maximum likelihood gaussian distribution fit:
使用直方图和最大似然高斯分布拟合绘制分布图:
```py
>>> from scipy.stats import norm
......@@ -115,7 +115,7 @@ Plot the distribution with a histogram and maximum likelihood gaussian distribut
![http://seaborn.pydata.org/_images/seaborn-distplot-4.png](img/d3a9c4026d4ce70e54b250057cd2062b.jpg)
Plot the distribution on the vertical axis:
在垂直轴上绘制分布图:
```py
>>> ax = sns.distplot(x, vertical=True)
......@@ -124,7 +124,7 @@ Plot the distribution on the vertical axis:
![http://seaborn.pydata.org/_images/seaborn-distplot-5.png](img/0a53d5e52e4ce61295a6c2b5fc4bf6c8.jpg)
Change the color of all the plot elements:
更改所有绘图元素的颜色:
```py
>>> sns.set_color_codes()
......@@ -134,7 +134,7 @@ Change the color of all the plot elements:
![http://seaborn.pydata.org/_images/seaborn-distplot-6.png](img/fac6ba03c6573e299e4eee00c32999fb.jpg)
Pass specific parameters to the underlying plot functions:
将特定参数传递给基础绘图函数:
```py
>>> ax = sns.distplot(x, rug=True, rug_kws={"color": "g"},
......@@ -144,4 +144,4 @@ Pass specific parameters to the underlying plot functions:
```
![http://seaborn.pydata.org/_images/seaborn-distplot-7.png](img/fce8e5a984297be3f6f8b5d4c5369a78.jpg)
\ No newline at end of file
![http://seaborn.pydata.org/_images/seaborn-distplot-7.png](img/fce8e5a984297be3f6f8b5d4c5369a78.jpg)
......@@ -4,90 +4,93 @@
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)
```
Fit and plot a univariate or bivariate kernel density estimate.
拟合并绘制单变量或双变量核密度估计图。
参数:`data`1d array-like
参数:`data`一维阵列
> Input data.
> 输入数据
**data2: 1d array-like, optional**
**data2:一维阵列,可选。
> Second input data. If present, a bivariate KDE will be estimated.
> 第二输入数据。如果存在,将估计双变量KDE。
`shade`bool, optional
`shade`布尔值,可选参数。
> If True, shade in the area under the KDE curve (or draw with filled contours when data is bivariate).
> 如果为True,则在KDE曲线下方的区域中增加阴影(或者在数据为双变量时使用填充的轮廓绘制)。
`vertical`bool, optional
`vertical`布尔值,可选参数。
> If True, density is on x-axis.
> 如果为True,密度图将显示在x轴。
`kernel`:{‘gau’ | ‘cos’ | ‘biw’ | ‘epa’ | ‘tri’ | ‘triw’ }, optional
`kernel`:{‘gau’ | ‘cos’ | ‘biw’ | ‘epa’ | ‘tri’ | ‘triw’ },可选参数
> Code for shape of kernel to fit with. Bivariate KDE can only use gaussian kernel.
> 要拟合的核的形状代码,双变量KDE只能使用高斯核。
`bw`:{‘scott’ | ‘silverman’ | scalar | pair of scalars }, optional
`bw`:{‘scott’ | ‘silverman’ | scalar | pair of scalars },可选参数
> Name of reference method to determine kernel size, scalar factor, or scalar for each dimension of the bivariate plot. Note that the underlying computational libraries have different interperetations for this parameter: `statsmodels` uses it directly, but `scipy` treats it as a scaling factor for the standard deviation of the data.
> 用于确定双变量图的每个维的核大小、标量因子或标量的参考方法的名称。需要注意的是底层的计算库对此参数有不同的交互:`statsmodels`直接使用它,而`scipy`将其视为数据标准差的缩放因子。
`gridsize`int, optional
`gridsize`整型数据,可选参数。
> Number of discrete points in the evaluation grid.
> 评估网格中的离散点数。
`cut`scalar, optional
`cut`标量,可选参数。
> Draw the estimate to cut * bw from the extreme data points.
> 绘制估计值以从极端数据点切割* bw。
`clip`pair of scalars, or pair of pair of scalars, optional
`clip`一对标量,可选参数。
> Lower and upper bounds for datapoints used to fit KDE. Can provide a pair of (low, high) bounds for bivariate plots.
> 用于拟合KDE图的数据点的上下限值。可以为双变量图提供一对(上,下)边界。
`legend`bool, optional
`legend`布尔值,可选参数。
> If True, add a legend or label the axes when possible.
> 如果为True,为绘制的图像添加图例或者标记坐标轴。
`cumulative`bool, optional
`cumulative`布尔值,可选参数。
> If True, draw the cumulative distribution estimated by the kde.
> 如果为True,则绘制kde估计图的累积分布。
`shade_lowest`bool, optional
`shade_lowest`布尔值,可选参数。
> If True, shade the lowest contour of a bivariate KDE plot. Not relevant when drawing a univariate plot or when `shade=False`. Setting this to `False` can be useful when you want multiple densities on the same Axes.
> 如果为True,则屏蔽双变量KDE图的最低轮廓。绘制单变量图或“shade = False”时无影响。当你想要在同一轴上绘制多个密度时,可将此参数设置为“False”。
`cbar`bool, optional
`cbar`布尔值,可选参数。
> If True and drawing a bivariate KDE plot, add a colorbar.
> 如果为True并绘制双变量KDE图,为绘制的图像添加颜色条。
`cbar_ax`:matplotlib axes, optional
`cbar_ax`:matplotlib axes,可选参数。
> Existing axes to draw the colorbar onto, otherwise space is taken from the main axes.
> 用于绘制颜色条的坐标轴,若为空,就在主轴绘制颜色条。
`cbar_kws`dict, optional
`cbar_kws`字典,可选参数。
> Keyword arguments for `fig.colorbar()`.
> `fig.colorbar()`的关键字参数。
`ax`:matplotlib axes, optional
`ax`:matplotlib axes,可选参数。
> Axes to plot on, otherwise uses current axes.
> 要绘图的坐标轴,若为空,则使用当前轴。
`kwargs`:key, value pairings
> Other keyword arguments are passed to `plt.plot()` or `plt.contour{f}` depending on whether a univariate or bivariate plot is being drawn.
`kwargs`:键值对
> 其他传递给`plt.plot()`或`plt.contour {f}`的关键字参数,具体取决于是绘制单变量还是双变量图。
返回值:`ax`:matplotlib Axes
> Axes with plot.
> 绘图的坐标轴。
**另请参见**
[`distplot`](seaborn.distplot.html#seaborn.distplot "seaborn.distplot")
灵活绘制单变量观测值分布图。
See also
[`jointplot`](seaborn.jointplot.html#seaborn.jointplot "seaborn.jointplot")
Flexibly plot a univariate distribution of observations.Plot a joint dataset with bivariate and marginal distributions.
绘制一个具有双变量和边缘分布的联合数据集。
Examples
范例
Plot a basic univariate density:
绘制一个简单的单变量分布:
```py
>>> import numpy as np; np.random.seed(10)
......@@ -100,7 +103,7 @@ Plot a basic univariate density:
![http://seaborn.pydata.org/_images/seaborn-kdeplot-1.png](img/467839dfd41d95bdf1eb6d992d54a81f.jpg)
Shade under the density curve and use a different color:
在密度曲线下使用不同的颜色着色:
```py
>>> ax = sns.kdeplot(x, shade=True, color="r")
......@@ -109,7 +112,7 @@ Shade under the density curve and use a different color:
![http://seaborn.pydata.org/_images/seaborn-kdeplot-2.png](img/98bd4d30d5719cd930a50603d08aa30e.jpg)
Plot a bivariate density:
绘制一个双变量分布:
```py
>>> ax = sns.kdeplot(x, y)
......@@ -118,7 +121,7 @@ Plot a bivariate density:
![http://seaborn.pydata.org/_images/seaborn-kdeplot-3.png](img/1a4a764cf63a098fe9db3dc317e88058.jpg)
Use filled contours:
使用填充轮廓:
```py
>>> ax = sns.kdeplot(x, y, shade=True)
......@@ -127,7 +130,7 @@ Use filled contours:
![http://seaborn.pydata.org/_images/seaborn-kdeplot-4.png](img/566a36de7b39f66e34fa323e7153fa42.jpg)
Use more contour levels and a different color palette:
使用更多的轮廓级别和不同的调色板:
```py
>>> ax = sns.kdeplot(x, y, n_levels=30, cmap="Purples_d")
......@@ -136,7 +139,7 @@ Use more contour levels and a different color palette:
![http://seaborn.pydata.org/_images/seaborn-kdeplot-5.png](img/73c68c911f3d8aaf827238e97a8dc560.jpg)
Use a narrower bandwith:
使用窄带宽:
```py
>>> ax = sns.kdeplot(x, bw=.15)
......@@ -145,7 +148,7 @@ Use a narrower bandwith:
![http://seaborn.pydata.org/_images/seaborn-kdeplot-6.png](img/cf85bc1dbfbb0399b3008f079b88d570.jpg)
Plot the density on the vertical axis:
在纵轴上绘制密度分布:
```py
>>> ax = sns.kdeplot(y, vertical=True)
......@@ -154,7 +157,7 @@ Plot the density on the vertical axis:
![http://seaborn.pydata.org/_images/seaborn-kdeplot-7.png](img/62b886998fa52840a228f283aa862506.jpg)
Limit the density curve within the range of the data:
将密度曲线限制在数据范围内:
```py
>>> ax = sns.kdeplot(x, cut=0)
......@@ -163,7 +166,7 @@ Limit the density curve within the range of the data:
![http://seaborn.pydata.org/_images/seaborn-kdeplot-8.png](img/1d21f3969de9de67e8acd0e2486c5e04.jpg)
Add a colorbar for the contours:
为轮廓添加一个颜色条:
```py
>>> ax = sns.kdeplot(x, y, cbar=True)
......@@ -172,7 +175,7 @@ Add a colorbar for the contours:
![http://seaborn.pydata.org/_images/seaborn-kdeplot-9.png](img/341dd0f98ddca59219e6289b038c8784.jpg)
Plot two shaded bivariate densities:
为双变量密度图绘制两个阴影:
```py
>>> iris = sns.load_dataset("iris")
......@@ -185,4 +188,4 @@ Plot two shaded bivariate densities:
```
![http://seaborn.pydata.org/_images/seaborn-kdeplot-10.png](img/6ffe5e9bcaba45c14f423cae61e6e743.jpg)
\ No newline at end of file
![http://seaborn.pydata.org/_images/seaborn-kdeplot-10.png](img/6ffe5e9bcaba45c14f423cae61e6e743.jpg)
......@@ -4,96 +4,95 @@
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)
```
Plot rectangular data as a color-encoded matrix.
将矩形数据绘制为颜色编码矩阵。
This is an Axes-level function and will draw the heatmap into the currently-active Axes if none is provided to the `ax` argument. Part of this Axes space will be taken and used to plot a colormap, unless `cbar` is False or a separate Axes is provided to `cbar_ax`.
这是一个坐标轴级的函数,如果没有提供给`ax`参数,它会将热力图绘制到当前活动的轴中。除非`cbar`为False或为`cbar_ax`提供单独的Axes,否则将使用此轴空间的一部分绘制颜色图。
参数:`data`rectangular dataset
参数:`data`矩形数据集
> 2D dataset that can be coerced into an ndarray. If a Pandas DataFrame is provided, the index/column information will be used to label the columns and rows.
> 可以强制转换为ndarray格式数据的2维数据集。如果提供了Pandas DataFrame数据,索引/列信息将用于标记列和行。
`vmin, vmax`floats, optional
`vmin, vmax`浮点型数据,可选参数。
> Values to anchor the colormap, otherwise they are inferred from the data and other keyword arguments.
> 用于锚定色彩映射的值,否则它们是从数据和其他关键字参数推断出来的。
`cmap`:matplotlib colormap name or object, or list of colors, optional
`cmap`:matplotlib 颜色条名称或者对象,或者是颜色列表,可选参数。
> The mapping from data values to color space. If not provided, the default will depend on whether `center` is set.
> 从数据值到颜色空间的映射。 如果没有提供,默认值将取决于是否设置了“center”。
`center`float, optional
`center`浮点数,可选参数。
> The value at which to center the colormap when plotting divergant data. Using this parameter will change the default `cmap` if none is specified.
> 绘制有色数据时将色彩映射居中的值。 如果没有指定,则使用此参数将更改默认的`cmap`。
`robust`bool, optional
`robust`布尔值,可选参数。
> If True and `vmin` or `vmax` are absent, the colormap range is computed with robust quantiles instead of the extreme values.
> 如果是True,并且`vmin`或`vmax`为空,则使用稳健分位数而不是极值来计算色彩映射范围。
`annot`:bool or rectangular dataset, optional
`annot`:布尔值或者矩形数据,可选参数。
> If True, write the data value in each cell. If an array-like with the same shape as `data`, then use this to annotate the heatmap instead of the raw data.
> 如果为True,则在每个热力图单元格中写入数据值。 如果数组的形状与`data`相同,则使用它来代替原始数据注释热力图。
`fmt`string, optional
`fmt`字符串,可选参数。
> String formatting code to use when adding annotations.
> 添加注释时要使用的字符串格式代码。
`annot_kws`dict of key, value mappings, optional
`annot_kws`字典或者键值对,可选参数。
> Keyword arguments for `ax.text` when `annot` is True.
> 当`annot`为True时,`ax.text`的关键字参数。
`linewidths`float, optional
`linewidths`浮点数,可选参数。
> Width of the lines that will divide each cell.
> 划分每个单元格的行的宽度。
`linecolor`color, optional
`linecolor`颜色,可选参数
> Color of the lines that will divide each cell.
> 划分每个单元的线条的颜色。
`cbar`boolean, optional
`cbar`布尔值,可选参数。
> Whether to draw a colorbar.
> 描述是否绘制颜色条。
`cbar_kws`dict of key, value mappings, optional
`cbar_kws`字典或者键值对,可选参数。
> Keyword arguments for <cite>fig.colorbar</cite>.
> *fig.colorbar*的关键字参数。
`cbar_ax`:matplotlib Axes, optional
`cbar_ax`:matplotlib Axes,可选参数。
> Axes in which to draw the colorbar, otherwise take space from the main Axes.
> 用于绘制颜色条的轴,否则从主轴获取。
`square`boolean, optional
`square`布尔值,可选参数。
> If True, set the Axes aspect to “equal” so each cell will be square-shaped.
> 如果为True,则将坐标轴方向设置为“equal”,以使每个单元格为方形。
`xticklabels, yticklabels`:“auto”, bool, list-like, or int, optional
`xticklabels, yticklabels`:“auto”,布尔值,类列表值,或者整形数值,可选参数。
> If True, plot the column names of the dataframe. If False, don’t plot the column names. If list-like, plot these alternate labels as the xticklabels. If an integer, use the column names but plot only every n label. If “auto”, try to densely plot non-overlapping labels.
> 如果为True,则绘制数据框的列名称。如果为False,则不绘制列名称。如果是列表,则将这些替代标签绘制为xticklabels。如果是整数,则使用列名称,但仅绘制每个n标签。如果是“auto”,将尝试密集绘制不重叠的标签。
`mask`boolean array or DataFrame, optional
`mask`布尔数组或者DataFrame数据,可选参数。
> If passed, data will not be shown in cells where `mask` is True. Cells with missing values are automatically masked.
> 如果为空值,数据将不会显示在`mask`为True的单元格中。 具有缺失值的单元格将自动被屏蔽。
`ax`:matplotlib Axes, optional
`ax`:matplotlib Axes,可选参数。
> Axes in which to draw the plot, otherwise use the currently-active Axes.
> 绘制图的坐标轴,否则使用当前活动的坐标轴。
`kwargs`:other keyword arguments
> All other keyword arguments are passed to `ax.pcolormesh`.
`kwargs`:其他关键字参数。
> 所有其他关键字参数都传递给`ax.pcolormesh`。
返回值:`ax`:matplotlib Axes
> Axes object with the heatmap.
> 热力图的轴对象。
**另请参见**
See also
[`clustermap`](seaborn.clustermap.html#seaborn.clustermap "seaborn.clustermap")
Plot a matrix using hierachical clustering to arrange the rows and columns.
使用分层聚类绘制矩阵以排列行和列。
Examples
范例
Plot a heatmap for a numpy array:
为numpy数组绘制热力图:
```py
>>> import numpy as np; np.random.seed(0)
......@@ -105,7 +104,7 @@ Plot a heatmap for a numpy array:
![http://seaborn.pydata.org/_images/seaborn-heatmap-1.png](img/2dcc622657bb409719bb9c747e0456c4.jpg)
Change the limits of the colormap:
更改默认的colormap范围:
```py
>>> ax = sns.heatmap(uniform_data, vmin=0, vmax=1)
......@@ -114,7 +113,7 @@ Change the limits of the colormap:
![http://seaborn.pydata.org/_images/seaborn-heatmap-2.png](img/6600f3e11ba368f49ec94d562dd39b4a.jpg)
Plot a heatmap for data centered on 0 with a diverging colormap:
使用发散色图绘制以0为中心的数据的热力图:
```py
>>> normal_data = np.random.randn(10, 12)
......@@ -124,7 +123,7 @@ Plot a heatmap for data centered on 0 with a diverging colormap:
![http://seaborn.pydata.org/_images/seaborn-heatmap-3.png](img/519a9ac2d3daa6dd6160e4f71bf0e342.jpg)
Plot a dataframe with meaningful row and column labels:
使用特定的行和列标签绘制dataframe:
```py
>>> flights = sns.load_dataset("flights")
......@@ -135,7 +134,7 @@ Plot a dataframe with meaningful row and column labels:
![http://seaborn.pydata.org/_images/seaborn-heatmap-4.png](img/dd89a846e99f54ceffc01f58b1545cc1.jpg)
Annotate each cell with the numeric value using integer formatting:
使用整数格式的数字值注释每个小单元格:
```py
>>> ax = sns.heatmap(flights, annot=True, fmt="d")
......@@ -144,7 +143,7 @@ Annotate each cell with the numeric value using integer formatting:
![http://seaborn.pydata.org/_images/seaborn-heatmap-5.png](img/e28bcf9d1f72aedbb18ec128da502f35.jpg)
Add lines between each cell:
在每个单元格之间添加线:
```py
>>> ax = sns.heatmap(flights, linewidths=.5)
......@@ -153,7 +152,7 @@ Add lines between each cell:
![http://seaborn.pydata.org/_images/seaborn-heatmap-6.png](img/970cf8333ec7a6b8eec115254ad34265.jpg)
Use a different colormap:
使用不同的colormap:
```py
>>> ax = sns.heatmap(flights, cmap="YlGnBu")
......@@ -162,7 +161,7 @@ Use a different colormap:
![http://seaborn.pydata.org/_images/seaborn-heatmap-7.png](img/e18cb02ed3ad1b91b540951f2912539b.jpg)
Center the colormap at a specific value:
将colormap置于特定值的中心:
```py
>>> ax = sns.heatmap(flights, center=flights.loc["January", 1955])
......@@ -171,7 +170,7 @@ Center the colormap at a specific value:
![http://seaborn.pydata.org/_images/seaborn-heatmap-8.png](img/cf3d8b2d64f574209d01cfe330f3927b.jpg)
Plot every other column label and don’t plot row labels:
绘制每个其他列标签,而不绘制行标签:
```py
>>> data = np.random.randn(50, 20)
......@@ -181,7 +180,7 @@ Plot every other column label and don’t plot row labels:
![http://seaborn.pydata.org/_images/seaborn-heatmap-9.png](img/a3dadd3fc0e3dcd7aba22164979fb558.jpg)
Don’t draw a colorbar:
不绘制颜色条:
```py
>>> ax = sns.heatmap(flights, cbar=False)
......@@ -190,7 +189,7 @@ Don’t draw a colorbar:
![http://seaborn.pydata.org/_images/seaborn-heatmap-10.png](img/be698c1c447b1398ee3d4501aef2415c.jpg)
Use different axes for the colorbar:
在不同的坐标轴方向绘制颜色条:
```py
>>> grid_kws = {"height_ratios": (.9, .05), "hspace": .3}
......@@ -203,7 +202,7 @@ Use different axes for the colorbar:
![http://seaborn.pydata.org/_images/seaborn-heatmap-11.png](img/be6577fc41adf407960f66d71436521f.jpg)
Use a mask to plot only part of a matrix
使用遮罩绘制矩阵中的一部分
```py
>>> corr = np.corrcoef(np.random.randn(10, 200))
......@@ -214,4 +213,4 @@ Use a mask to plot only part of a matrix
```
![http://seaborn.pydata.org/_images/seaborn-heatmap-12.png](img/f683b3bba7ec2d231b917ed55aa858d1.jpg)
\ No newline at end of file
![http://seaborn.pydata.org/_images/seaborn-heatmap-12.png](img/f683b3bba7ec2d231b917ed55aa858d1.jpg)
......@@ -4,93 +4,103 @@
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)
```
Multi-plot grid for plotting conditional relationships.
用于绘制条件关系的多图网格。
```py
__init__(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)
```
Initialize the matplotlib figure and FacetGrid object.
初始化matplotlib画布和FacetGrid对象。
This class maps a dataset onto multiple axes arrayed in a grid of rows and columns that correspond to _levels_ of variables in the dataset. The plots it produces are often called “lattice”, “trellis”, or “small-multiple” graphics.
该类将数据集映射到由行和列组成的网格中的多个轴上,这些轴与数据集中变量的级别对应。它产生的图通常被称为“lattice”,“trellis”或“small-multiple”图形。
It can also represent levels of a third varaible 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”参数。
When using seaborn functions that infer semantic mappings from a dataset, care must be taken to synchronize those mappings across facets. In most cases, it will be better to use a figure-level function (e.g. [`relplot()`](seaborn.relplot.html#seaborn.relplot "seaborn.relplot") or [`catplot()`](seaborn.catplot.html#seaborn.catplot "seaborn.catplot")) than to use [`FacetGrid`](#seaborn.FacetGrid "seaborn.FacetGrid") directly.
当使用从数据集推断语义映射的seaborn函数时,必须注意在各个方面之间同步这些映射。在大多数情况下,使用图形级函数(例如[`relplot()`](seaborn.relplot.html#seaborn.relplot "seaborn.relplot")[`catplot()`](seaborn.catplot.html#seaborn.catplot "seaborn.catplot"))比直接使用[`FacetGrid`](seaborn.FacetGrid.html#seaborn.FacetGrid "seaborn.FacetGrid")更好。
The basic workflow is to initialize the [`FacetGrid`](#seaborn.FacetGrid "seaborn.FacetGrid") object with the dataset and the variables that are used to structure the grid. Then one or more plotting functions can be applied to each subset by calling [`FacetGrid.map()`](seaborn.FacetGrid.map.html#seaborn.FacetGrid.map "seaborn.FacetGrid.map") or [`FacetGrid.map_dataframe()`](seaborn.FacetGrid.map_dataframe.html#seaborn.FacetGrid.map_dataframe "seaborn.FacetGrid.map_dataframe"). Finally, the plot can be tweaked with other methods to do things like change the axis labels, use different ticks, or add a legend. See the detailed code examples below for more information.
基本工作流程是使用数据集和用于构造网格的变量初始化FacetGrid对象。然后,通过调用[`FacetGrid.map()`](seaborn.FacetGrid.map.html#seaborn.FacetGrid.map "seaborn.FacetGrid.map")[`FacetGrid.map_dataframe()`](seaborn.FacetGrid.map_dataframe.html#seaborn.FacetGrid.map_dataframe "seaborn.FacetGrid.map_dataframe"),可以将一个或多个绘图函数应用于每个子集。最后,可以使用其他方法调整绘图,以执行更改轴标签、使用不同刻度或添加图例等操作。有关详细信息,请参阅下面的详细代码示例。
See the [tutorial](../tutorial/axis_grids.html#grid-tutorial) for more information.
更多相关信息请参阅[`教程`](../tutorial/axis_grids.html#grid-tutorial)
参数:`data`:DataFrame
参数:`data`:DataFrame数据。
> Tidy (“long-form”) dataframe where each column is a variable and each row is an observation.
> 整洁的(“长形式”)dataframe数据,其中每一列是一个变量,每一行是一个观察实例。
`row, col, hue`strings
`row, col, hue`字符串。
> 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`参数以控制此变量的级别顺序。
`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.
> 以此参数值来限制网格的列维度,以便列面跨越多行。与`row`面不兼容。
`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,则跨列共享y轴或者跨行共享x轴。
`height`scalar, optional
`height`标量,可选参数。
> Height (in inches) of each facet. See also: `aspect`.
> 每个图片的高度设定(以英寸为单位)。另见:*aspect*
`aspect`scalar, optional
`aspect`标量,可选参数。
> Aspect ratio of each facet, so that `aspect * height` gives the width of each facet in inches.
> 每个图片的纵横比,因此aspect * height给出每个图片的宽度,单位为英寸。
`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.
> 用于色调变量的不同级别的颜色。应为[`color_palette()`](seaborn.color_palette.html#seaborn.color_palette "seaborn.color_palette")可以解释的参数,或者是将色调级别映射到matplotlib颜色的字典。
`{row,col,hue}_order`lists, optional
`{row,col,hue}_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.
> 对所给命令级别进行排序。默认情况下,这将是在数据中显示的级别,或者,如果变量是pandas分类,则为类别顺序。
`hue_kws`dictionary of param -> list of values mapping
`hue_kws`参数-列表值的映射字典
> Other keyword arguments to insert into the plotting call to let other plot attributes vary across levels of the hue variable (e.g. the markers in a scatterplot).
> 插入到绘图调用中的其他关键字参数,使得其他绘图属性在色调变量的级别上有所不同(例如散点图中的标记)。
`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,则图形尺寸将被扩展,图例将绘制在中间右侧的图形之外。
`despine`boolean, optional
`despine`布尔值,可选参数。
> Remove the top and right spines from the plots.
> 从图中移除顶部和右侧边缘框架。
`margin_titles`bool, optional
`margin_titles`布尔值,可选参数。
> If `True`, the titles for the row variable are drawn to the right of the last column. This option is experimental and may not work in all cases.
> 如果为True,则行变量的标题将绘制在最后一列的右侧。此选项是实验性的,可能无法在所有情况下使用。
**{x, y}lim: tuples, optional**
`{x, y}lim`:元组,可选参数。
> Limits for each of the axes on each facet (only relevant when share{x, y} is True.
> 每个图片上每个轴的限制(仅当share {x,y}为True时才相关)。
`subplot_kws`dict, optional
`subplot_kws`字典,可选参数。
> Dictionary of keyword arguments passed to matplotlib subplot(s) methods.
> 传递给matplotlib subplot(s)方法的关键字参数字典。
`gridspec_kws`dict, optional
`gridspec_kws`字典,可选参数。
> Dictionary of keyword arguments passed to matplotlib’s `gridspec` module (via `plt.subplots`). Requires matplotlib >= 1.4 and is ignored if `col_wrap` is not `None`.
> 传递给matplotlib的`gridspec`模块(通过`plt.subplots`)的关键字参数字典。需要matplotlib> = 1.4,如果`col_wrap`不是`None`,则忽略它。
**另请参见**
用于绘制成对关系的子图网格。
See also
[`relplot`](#seaborn.relplot "seaborn.relplot")
Subplot grid for plotting pairwise relationships.Combine a relational plot and a [`FacetGrid`](#seaborn.FacetGrid "seaborn.FacetGrid").Combine a categorical plot and a [`FacetGrid`](#seaborn.FacetGrid "seaborn.FacetGrid").Combine a regression plot and a [`FacetGrid`](#seaborn.FacetGrid "seaborn.FacetGrid").
结合关系图和[`FacetGrid`](#seaborn.FacetGrid "seaborn.FacetGrid")
Examples
[`catplot`](#seaborn.catplot "seaborn.catplot")
Initialize a 2x2 grid of facets using the tips dataset:
结合分类图和[`FacetGrid`](#seaborn.FacetGrid "seaborn.FacetGrid")
[`lmplot`](#seaborn.lmplot "seaborn.lmplot")
结合回归图和[`FacetGrid`](#seaborn.FacetGrid "seaborn.FacetGrid")
范例
使用tips数据集初始化2x2网格图:
```py
>>> import seaborn as sns; sns.set(style="ticks", color_codes=True)
......@@ -101,7 +111,7 @@ Initialize a 2x2 grid of facets using the tips dataset:
![http://seaborn.pydata.org/_images/seaborn-FacetGrid-1.png](img/b8699392ad92687d3ac264d00b00ec9b.jpg)
Draw a univariate plot on each facet:
在每个子图绘制一个单变量图:
```py
>>> import matplotlib.pyplot as plt
......@@ -112,9 +122,9 @@ Draw a univariate plot on each facet:
![http://seaborn.pydata.org/_images/seaborn-FacetGrid-2.png](img/ee99e47d6e0d2262037bca2e7fdb9772.jpg)
(Note that it’s not necessary to re-catch the returned variable; it’s the same object, but doing so in the examples makes dealing with the doctests somewhat less annoying).
(注意,没有必要重新捕获返回的变量;它是相同的对象,但在示例中这样做使得处理doctests更加方便)。
Pass additional keyword arguments to the mapped function:
将其他关键字参数传递给映射函数:
```py
>>> import numpy as np
......@@ -126,7 +136,7 @@ Pass additional keyword arguments to the mapped function:
![http://seaborn.pydata.org/_images/seaborn-FacetGrid-3.png](img/7bd763d402e774603d6f5e7c48c2369a.jpg)
Plot a bivariate function on each facet:
在每个子图绘制一个双变量函数:
```py
>>> g = sns.FacetGrid(tips, col="time", row="smoker")
......@@ -136,7 +146,7 @@ Plot a bivariate function on each facet:
![http://seaborn.pydata.org/_images/seaborn-FacetGrid-4.png](img/2aca4924009e92a55bc1579fc086d36c.jpg)
Assign one of the variables to the color of the plot elements:
将其中一个变量分配给绘图元素的颜色:
```py
>>> g = sns.FacetGrid(tips, col="time", hue="smoker")
......@@ -147,7 +157,7 @@ Assign one of the variables to the color of the plot elements:
![http://seaborn.pydata.org/_images/seaborn-FacetGrid-5.png](img/c53a49f5b838d50776627fc8910138ce.jpg)
Change the height and aspect ratio of each facet:
更改每个子图的高度和纵横比:
```py
>>> g = sns.FacetGrid(tips, col="day", height=4, aspect=.5)
......@@ -157,7 +167,7 @@ Change the height and aspect ratio of each facet:
![http://seaborn.pydata.org/_images/seaborn-FacetGrid-6.png](img/ca19289fa3db7f35bf27fa3f09db128e.jpg)
Specify the order for plot elements:
指定绘图元素的顺序:
```py
>>> g = sns.FacetGrid(tips, col="smoker", col_order=["Yes", "No"])
......@@ -167,7 +177,7 @@ Specify the order for plot elements:
![http://seaborn.pydata.org/_images/seaborn-FacetGrid-7.png](img/d84004bd86dc3645488324a3fbb3b060.jpg)
Use a different color palette:
使用不同的调色板:
```py
>>> kws = dict(s=50, linewidth=.5, edgecolor="w")
......@@ -180,7 +190,7 @@ Use a different color palette:
![http://seaborn.pydata.org/_images/seaborn-FacetGrid-8.png](img/fe9b97ad8c3e66c3a2514249fcd62ee6.jpg)
Use a dictionary mapping hue levels to colors:
使用字典将色调级别映射到颜色:
```py
>>> pal = dict(Lunch="seagreen", Dinner="gray")
......@@ -193,7 +203,7 @@ Use a dictionary mapping hue levels to colors:
![http://seaborn.pydata.org/_images/seaborn-FacetGrid-9.png](img/9299602c8a3b49e2a9095ad9ea69f07f.jpg)
Additionally use a different marker for the hue levels:
另外,为色调级别使用不同的标记:
```py
>>> g = sns.FacetGrid(tips, col="sex", hue="time", palette=pal,
......@@ -206,7 +216,7 @@ Additionally use a different marker for the hue levels:
![http://seaborn.pydata.org/_images/seaborn-FacetGrid-10.png](img/92494d907a4bd738426ff755349e4992.jpg)
“Wrap” a column variable with many levels into the rows:
将包含多个级别的列变量“换行”到行中:
```py
>>> att = sns.load_dataset("attention")
......@@ -217,7 +227,7 @@ Additionally use a different marker for the hue levels:
![http://seaborn.pydata.org/_images/seaborn-FacetGrid-11.png](img/3a3de5e84041d929dbf5cbade67f93e6.jpg)
Define a custom bivariate function to map onto the grid:
定义一个自定义双变量函数来映射到网格:
```py
>>> from scipy import stats
......@@ -233,7 +243,7 @@ Define a custom bivariate function to map onto the grid:
![http://seaborn.pydata.org/_images/seaborn-FacetGrid-12.png](img/a84563a49e5578ddeff33795280887f1.jpg)
Define a custom function that uses a `DataFrame` object and accepts column names as positional variables:
定义一个使用`DataFrame`对象的自定义函数,并接受列名作为位置变量:
```py
>>> import pandas as pd
......@@ -254,7 +264,7 @@ Define a custom function that uses a `DataFrame` object and accepts column names
![http://seaborn.pydata.org/_images/seaborn-FacetGrid-13.png](img/2017a8a703bdcc077baea030a758721d.jpg)
Use different axes labels after plotting:
绘图后使用不同的轴标签:
```py
>>> g = sns.FacetGrid(tips, col="smoker", row="sex")
......@@ -265,7 +275,7 @@ Use different axes labels after plotting:
![http://seaborn.pydata.org/_images/seaborn-FacetGrid-14.png](img/52d5efab2c08ec72873b3e66fea66d14.jpg)
Set other attributes that are shared across the facetes:
设置每个子图共享的其他属性:
```py
>>> g = sns.FacetGrid(tips, col="smoker", row="sex")
......@@ -277,7 +287,7 @@ Set other attributes that are shared across the facetes:
![http://seaborn.pydata.org/_images/seaborn-FacetGrid-15.png](img/308a2f3dd32f77b25254d6650cce7be8.jpg)
Use a different template for the facet titles:
为子图标题使用不同的模板:
```py
>>> g = sns.FacetGrid(tips, col="size", col_wrap=3)
......@@ -288,7 +298,7 @@ Use a different template for the facet titles:
![http://seaborn.pydata.org/_images/seaborn-FacetGrid-16.png](img/b68bba1b9871f75b818870d08a9e3523.jpg)
Tighten the facets:
收紧每个子图:
```py
>>> g = sns.FacetGrid(tips, col="smoker", row="sex",
......@@ -302,24 +312,38 @@ Tighten the facets:
![http://seaborn.pydata.org/_images/seaborn-FacetGrid-17.png](img/30bd1c7aa657fabb90851a094c8d0a1e.jpg)
Methods
| [`__init__`](#seaborn.FacetGrid.__init__ "seaborn.FacetGrid.__init__")(data[, row, col, hue, col_wrap, …]) | Initialize the matplotlib figure and FacetGrid object. |
| `add_legend`([legend_data, title, label_order]) | Draw a legend, maybe placing it outside axes and resizing the figure. |
| `despine`(**kwargs) | Remove axis spines from the facets. |
| `facet_axis`(row_i, col_j) | Make the axis identified by these indices active and return it. |
| `facet_data`() | Generator for name indices and data subsets for each facet. |
| [`map`](seaborn.FacetGrid.map.html#seaborn.FacetGrid.map "seaborn.FacetGrid.map")(func, *args, **kwargs) | Apply a plotting function to each facet’s subset of the data. |
| [`map_dataframe`](seaborn.FacetGrid.map_dataframe.html#seaborn.FacetGrid.map_dataframe "seaborn.FacetGrid.map_dataframe")(func, *args, **kwargs) | Like `.map` but passes args as strings and inserts data in kwargs. |
| `savefig`(*args, **kwargs) | Save the figure. |
| `set`(**kwargs) | Set attributes on each subplot Axes. |
| `set_axis_labels`([x_var, y_var]) | Set axis labels on the left column and bottom row of the grid. |
| `set_titles`([template, row_template, …]) | Draw titles either above each facet or on the grid margins. |
| `set_xlabels`([label]) | Label the x axis on the bottom row of the grid. |
| `set_xticklabels`([labels, step]) | Set x axis tick labels on the bottom row of the grid. |
| `set_ylabels`([label]) | Label the y axis on the left column of the grid. |
| `set_yticklabels`([labels]) | Set y axis tick labels on the left column of the grid. |
Attributes
| `ax` | Easy access to single axes. |
\ No newline at end of file
方法
| [`__init__`](#seaborn.FacetGrid.__init__ "seaborn.FacetGrid.__init__")(data[, row, col, hue, col_wrap, …]) | 初始化matplotlib画布和FacetGrid对象。 |
| `add_legend`([legend_data, title, label_order]) | 绘制一个图例,可能将其放在轴外并调整图形大小。|
| `despine`(\**kwargs) | 从子图中移除轴的边缘框架。 |
| `facet_axis`(row_i, col_j) | 使这些索引识别的轴处于活动状态并返回。 |
| `facet_data`() | 用于每个子图的名称索引和数据子集的生成器。 |
| [`map`](seaborn.FacetGrid.map.html#seaborn.FacetGrid.map "seaborn.FacetGrid.map")(func, *args, \**kwargs) | 将绘图功能应用于每个子图的数据子集。 |
| [`map_dataframe`](seaborn.FacetGrid.map_dataframe.html#seaborn.FacetGrid.map_dataframe "seaborn.FacetGrid.map_dataframe")(func, *args, \**kwargs) | 像`.map`一样,但是将args作为字符串传递并在kwargs中插入数据。 |
| `savefig`(*args, \**kwargs) | 保存图片。 |
| `set`(\**kwargs) | 在每个子图集坐标轴上设置属性。|
| `set_axis_labels`([x_var, y_var]) | 在网格的左列和底行设置轴标签。 |
| `set_titles`([template, row_template, …]) | 在每个子图上方或网格边缘绘制标题。 |
| `set_xlabels`([label]) | 在网格的底行标记x轴。 |
| `set_xticklabels`([labels, step]) | 在网格的底行设置x轴刻度标签。 |
| `set_ylabels`([label]) | 在网格的左列标记y轴。 |
| `set_yticklabels`([labels]) | 在网格的左列上设置y轴刻度标签。 |
属性
| `ax` | 轻松访问单个坐标轴。 |
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册