我有一些几何分布的数据。当我想看它时,我使用
sns.distplot(data, kde=False, norm_hist=True, bins=100)
结果是一张图片:
但是,箱的高度加起来不等于 1,这意味着 y 轴不显示概率,这是不同的东西。如果我们使用
weights = np.ones_like(np.array(data))/float(len(np.array(data)))
plt.hist(data, weights=weights, bins = 100)
y 轴应显示概率,因为箱高度总和为 1:
这里可以看得更清楚:假设我们有一个列表
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)
我们得到:
如您所见,第 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)
我们得到:
而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/