使用 distplot 绘制直方图时 y 轴的单位是什么?

What is the unit of the y-axis when using distplot to plot a histogram?

使用distplot绘制直方图时,y轴的单位是什么?我绘制了不同的直方图和正常拟合,我看到在一种情况下,它的范围是 0 到 0.9,而在另一种情况下,它的范围是 0 到 4.5。

来自 help(sns.distplot)

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

A density 被缩放,因此曲线下的面积为 1,因此没有任何一个 bin 会高于 1(整个数据集)。但是 kde 默认情况下是 True 并覆盖 norm_hist,因此 norm_hist 仅当您将 kde 明确设置为 False 时才会更改 y 单位:

import matplotlib.pyplot as plt
import numpy as np
import seaborn as sns

fig, axs = plt.subplots(figsize=(6,6), ncols=2, nrows=2)
data = np.random.randint(0,20,40)

for row in (0,1):
    for col in (0,1):
        sns.distplot(data, kde=row, norm_hist=col, ax=axs[row, col])

axs[0,0].set_ylabel('NO kernel density')
axs[1,0].set_ylabel('KDE on')
axs[1,0].set_xlabel('norm_hist=False')
axs[1,1].set_xlabel('norm_hist=True')