首页 > 解决方案 > 为什么 distplot 改变绘制值的范围?

问题描述

我有一个值数组,我试图为其拟合概率密度函数。我使用 distplot 绘制了直方图,如下所示:

x = [  17.56,
 162.52,
 172.58,
 160.82,
 182.14,
 165.86,
 242.06,
 135.76,
 122.86,
 230.22,
 208.66,
 271.36,
 122.68,
 188.42,
 171.82,
 102.30,
 196.40,
 107.38,
 192.35,
 179.66,
 173.30,
 254.66,
 176.12,
 75.365,
 135.78,
 103.66,
 183.50,
 166.08,
 207.66,
 146.22,
 151.19,
 172.20,
 103.41,
 133.93,
 186.48,]
sns.distplot(x)

情节如下所示: 在此处输入图像描述

我在数组中的最小值是 17,最大值是 250 左右,所以我不明白图中 x 轴的范围,因为我也没有添加任何参数。sns.displot绘图前是否对数据进行标准化?

标签: pythonseaborn

解决方案


kde 曲线在数据点上拟合许多高斯正态曲线。这样一条法线曲线有一条无限的尾巴,当它足够接近零高度时,它就会被切断。

请注意,自 seaborn 0.11 以来sns.distplot已弃用,并由 (在这种情况下) 取代sns.histplot(..., kde=True)。新的kdeplot有一个cut=默认为零的参数,在数据限制处切割曲线(cutkde_kwsin之一histplotsns.histplot(x, kde=True, kde_kws={'cut': 0}).

import seaborn as sns

x = [17.56, 162.52, 172.58, 160.82, 182.14, 165.86, 242.06, 135.76, 122.86, 230.22, 208.66, 271.36, 122.68, 188.42,
     171.82, 102.30, 196.40, 107.38, 192.35, 179.66, 173.30, 254.66, 176.12, 75.365, 135.78, 103.66, 183.50, 166.08,
     207.66, 146.22, 151.19, 172.20, 103.41, 133.93, 186.48]
sns.histplot(x, kde=True)

histplot 与 kde,切断数据限制


推荐阅读