使用 distplot 绘制直方图时 y 轴的单位是什么? [英] What is the unit of the y-axis when using distplot to plot a histogram?

查看:46
本文介绍了使用 distplot 绘制直方图时 y 轴的单位是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

What is the unit of the y-axis when using distplot to plot a histogram? I have plotted different histograms together with a normal fit and I see that in one case, it has a range of 0 to 0.9 while in another a range of 0 to 4.5.

推荐答案

来自 help(sns.distplot):

norm_hist:bool,可选如果为 True,则直方图高度显示密度而不是计数.如果绘制了 KDE 或拟合密度,则暗示了这一点.

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.

密度 被缩放,以便曲线下的面积为 1,因此没有单个 bin 会高于 1(整个数据集).但是 kde 默认为 True 并覆盖 norm_hist,所以 norm_hist 仅在您明确设置时更改 y 单位kdeFalse:

A density is scaled so that the area under the curve is 1, so no individual bin will ever be taller than 1 (the whole dataset). But kde is True by default and overrides norm_hist, so norm_hist changes the y-units only if you explicitly set kde to False:

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')

这篇关于使用 distplot 绘制直方图时 y 轴的单位是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆