【发布时间】:2018-09-20 11:02:49
【问题描述】:
我尝试使用来自numpy.random.normal documentation 的示例绘制归一化直方图。为此,我生成了正态分布的随机样本。
mu_true = 0
sigma_true = 0.1
s = np.random.normal(mu_true, sigma_true, 2000)
然后我将正态分布拟合到数据并计算 pdf。
mu, sigma = stats.norm.fit(s)
points = np.linspace(stats.norm.ppf(0.01,loc=mu,scale=sigma),
stats.norm.ppf(0.9999,loc=mu,scale=sigma),100)
pdf = stats.norm.pdf(points,loc=mu,scale=sigma)
显示拟合的 pdf 和数据直方图。
plt.hist(s, 30, density=True);
plt.plot(points, pdf, color='r')
plt.show()
我使用density=True,但很明显,pdf 和直方图没有标准化。
对于绘制真正归一化的直方图和 pdf 有什么建议?
Seaborn distplot 也不能解决问题。
import seaborn as sns
ax = sns.distplot(s)
【问题讨论】:
-
只是让您知道:Seaborn 的
distplot完成了所有这些工作。 -
谢谢。但这无济于事。我已经编辑了问题。
-
你确定它没有标准化吗?直方图下方的区域是多少?
-
总面积为 1。我被垃圾箱的高度弄糊涂了。但现在一切都清楚了
标签: python matplotlib histogram