Python 使用 distplot 绘制直方图时 y 轴的单位是什么?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/29788246/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
What is the unit of the y-axis when using distplot to plot a histogram?
提问by Harry
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.
使用 distplot 绘制直方图时 y 轴的单位是什么?我已经绘制了不同的直方图和正常拟合,我看到在一种情况下,它的范围是 0 到 0.9,而在另一种情况下,它的范围是 0 到 4.5。
采纳答案by cphlewis
From help(sns.distplot)
:
来自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.
norm_hist
: bool, otional 如果为 True,则直方图高度显示密度而不是计数。如果绘制了 KDE 或拟合密度,则暗示了这一点。
A densityis 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
:
甲密度被标定,因此,曲线下面积为1,所以没有独立的贮藏将永远是高度大于1(整个数据集)。但默认情况下kde
是True
overrides norm_hist
,因此norm_hist
仅当您明确设置kde
为时才更改 y 单位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')