seaborn 的 distplot 参数用于什么?

What are the arguments of seaborn's distplot used for?

我正在处理 titanic 数据集。为了可视化数据分布,我使用了 seaborn 绘图方法。但是我无法理解 distplot 的论点及其最终输出。 我想知道以下几行中使用的参数(参数)的使用,特别是 binsaxes[0]kde = False.

的使用
ax = sns.distplot(women[women['Survived']==1].Age.dropna(), bins=18, 
                  label = survived, ax = axes[0], kde =False)

ax = sns.distplot(women[women['Survived']==0].Age.dropna(), bins=40, 
                  label = not_survived, ax = axes[0], kde =False)

我已经在文档中搜索了distplot并上网了,但是没有写清楚

  1. 轴[0]

根据您的代码,我假设 axes 应该是 Axes 个对象的列表,而 axes[0] 意味着您访问列表中的第一个对象。当你使用 ax=axes[0] 意味着你希望你的情节在左边。请看这个 .

  1. kde=假

默认情况下,seaborn 会同时绘制 kernel density estimation 和直方图,kde=False 意味着你想隐藏它只显示直方图。

  1. 垃圾箱

从统计学上讲,直方图是一种 non-parametric 估计,其形状反映了数据的分布。箱子的数量会影响形状。因此,如果您希望您的绘图代表您的数据分布,您不应该只是随机选择一个 bin 编号。决定适当的 bin 数量的最常见方法是使用 Freedman–Diaconis rule,这也是 .distplot() 中的默认设置。也就是说,当你使用.distplot()函数显示数据分布时,最好不要指定bin参数。

首先,我们试着了解什么是distplot? Distplot 是 seaborn python 库的一个函数。表示如下:sns.seaborn().

它用于绘制 seaborn 直方图

现在,你脑子里的疑问可能来了,为什么我会绘制直方图。直方图有助于以条形图可视化数字类型数据集。

在 y 轴上给出数字数据集,正如您给出的 "women['Survived']==1"[women['Survived']==0]

在 x 轴上给出 bin。这意味着在特定范围内分发给定的数据集,并按照您给定的 bins= 18bins = 40 显示在条形图中 enter image description here

现在,我将展示 seaborn 的语法 sns.distplot()

Syntax: sns.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 histogram using sns.distplot