python - seaborn distplot中的y轴是什么?

标签 python matplotlib seaborn

我有一些几何分布的数据。当我想看它时,我使用

sns.distplot(data, kde=False, norm_hist=True, bins=100)

结果是一张图片:

Plot 1a

但是,箱的高度加起来不等于 1,这意味着 y 轴不显示概率,这是不同的东西。如果我们使用

weights = np.ones_like(np.array(data))/float(len(np.array(data)))
plt.hist(data, weights=weights, bins = 100)

y 轴应显示概率,因为箱高度总和为 1:

Plot 1b

这里可以看得更清楚:假设我们有一个列表

l = [1, 3, 2, 1, 3]

我们有两个 1、两个 3 和一个 2,所以它们各自的概率是 2/5、2/5 和 1/5。当我们使用带有 3 个 bin 的 seaborn histplot 时:

sns.distplot(l, kde=False, norm_hist=True, bins=3)

我们得到:

Plot 2a

如您所见,第 1 个和第 3 个 bin 之和为 0.6+0.6=1.2,这已经大于 1,因此 y 轴不是概率。当我们使用

weights = np.ones_like(np.array(l))/float(len(np.array(l)))
plt.hist(l, weights=weights, bins = 3)

我们得到:

enter image description here

而y轴是概率,如预期的0.4+0.4+0.2=1。

这两种情况下的 bin 数量对于每种情况下使用的两种方法都是相同的:100 个 bin 用于几何分布的数据,3 个 bin 用于具有 3 个可能值的小数组 l。所以垃圾箱的数量不是问题。

我的问题是:在以 norm_hist=True 调用的 seaborn distplot 中,y 轴是什么意思?

最佳答案

来自 documentation :

norm_hist : bool, optional

If True, the histogram height shows a density rather than a count. This is implied if a KDE or fitted density is plotted.

因此,您还需要考虑 bin 宽度,即计算曲线下的面积,而不仅仅是计算 bin 高度的总和。

关于python - seaborn distplot中的y轴是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51666784/

相关文章:

python - future 警告 : Conversion of the second argument of issubdtype from `float` to `np.floating` is deprecated

python - 将非线性比例与 Seaborn 热图一起使用

python - Seaborn countplot,每组归一化 y 轴

matplotlib - 可视化 :-x-labels and title for the graph created through matplotlib and seaborn are not displaying properly

python - 鼠标悬停在物体上时的声音效果?

python - r+ 和 w+ 模式之间的确切区别是什么?

python - 为什么 date_range 给出的结果与 DataFrame Pandas 日期的索引 [] 不同?

python - 如何生成具有足够间距以容纳大量数字的曲线图

python - matplotlib 中的轮廓未绘制指定数量的轮廓

python - 如何在 matplotlib 中绘制和使用 NaN 值