提交 6e2ab5df 编写于 作者: 落晓o's avatar 落晓o

Update 25.md

上级 20c2dbe6
# 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)
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册