在seaborn直方图上添加标准的正常pdf

abu*_*abu 1 python distribution seaborn

我想在使用seaborn.

import numpy as np
import seaborn as sns 
x = np.random.standard_normal(1000)
sns.distplot(x, kde = False)
Run Code Online (Sandbox Code Playgroud)

任何帮助,将不胜感激!

Bon*_*fum 7

scipy.stats.norm可以轻松访问具有
已知参数的正态分布的 pdf ;默认情况下,它对应于标准法线,mu=0,sigma=1。

为了使其与您的采样数据正确对应,直方图应
显示密度而不是计数,因此请norm_hist=Trueseaborn.distplot调用中使用。

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)                                                     
Run Code Online (Sandbox Code Playgroud)

样本和理论分布