在海洋直方图上添加标准普通pdf [英] Add a standard normal pdf over a seaborn histogram
本文介绍了在海洋直方图上添加标准普通pdf的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想在使用 seaborn
构建的直方图上添加标准的正常pdf曲线.
将numpy导入为np将seaborn导入为snsx = np.random.standard_normal(1000)sns.distplot(x,kde = False)
任何帮助将不胜感激!
解决方案
I would like to add a standard normal pdf curve over a histogram built with seaborn
.
import numpy as np
import seaborn as sns
x = np.random.standard_normal(1000)
sns.distplot(x, kde = False)
Any help would be appreciated!
解决方案
scipy.stats.norm
gives easy access to the pdf of a normal distribution with
known parameters; by default it corresponds to the standard normal, mu=0, sigma=1.
For this to correspond correctly to your sampled data, the histogram should
display densities and not counts, so use norm_hist=True
in the seaborn.distplot
call.
import numpy as np
import seaborn as sns
from scipy import stats
import matplotlib.pyplot as plt
x = np.random.standard_normal(1000)
ax = sns.distplot(x, kde = False, norm_hist=True)
# calculate the pdf over a range of values
xx = np.arange(-4, +4, 0.001)
yy = stats.norm.pdf(xx)
# and plot on the same axes that seaborn put the histogram
ax.plot(xx, yy, 'r', lw=2)
这篇关于在海洋直方图上添加标准普通pdf的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文