【发布时间】:2019-03-25 07:45:25
【问题描述】:
我想在使用seaborn 构建的直方图上添加标准正态 pdf 曲线。
import numpy as np
import seaborn as sns
x = np.random.standard_normal(1000)
sns.distplot(x, kde = False)
任何帮助将不胜感激!
【问题讨论】:
标签: python seaborn histogram distribution
我想在使用seaborn 构建的直方图上添加标准正态 pdf 曲线。
import numpy as np
import seaborn as sns
x = np.random.standard_normal(1000)
sns.distplot(x, kde = False)
任何帮助将不胜感激!
【问题讨论】:
标签: python seaborn histogram distribution
scipy.stats.norm 可让您轻松访问正态分布的 pdfmu=0,sigma=1。
mu=0 或 mu=10),此答案都有效python 3.8.11、matplotlib 3.4.2、seaborn 0.11.2 中测试import numpy as np
import seaborn as sns
from scipy import stats
import matplotlib.pyplot as plt
# data
np.random.seed(365)
x = np.random.standard_normal(1000)
seaborn.histplotax = sns.histplot(x, kde=False, stat='density', label='samples')
# calculate the pdf
x0, x1 = ax.get_xlim() # extract the endpoints for the x-axis
x_pdf = np.linspace(x0, x1, 100)
y_pdf = scipy.stats.norm.pdf(x_pdf)
ax.plot(x_pdf, y_pdf, 'r', lw=2, label='pdf')
ax.legend()
seaborn.distplot - 已弃用seaborn.distplot 调用中使用 norm_hist=True。ax = sns.distplot(x, kde = False, norm_hist=True, hist_kws={'ec': 'k'}, label='samples')
# calculate the pdf
x0, x1 = ax.get_xlim() # extract the endpoints for the x-axis
x_pdf = np.linspace(x0, x1, 100)
y_pdf = scipy.stats.norm.pdf(x_pdf)
ax.plot(x_pdf, y_pdf, 'r', lw=2, label='pdf')
ax.legend()
【讨论】: