您可以使用 matplotlib绘制直方图和 PDF (如@MrE 答案中的链接所示)。为了适应和计算 PDF,您可以使用 scipy.stats.norm,如下所示。
import numpy as np
from scipy.stats import norm
import matplotlib.pyplot as plt
# Generate some data for this demonstration.
data = norm.rvs(10.0, 2.5, size=500)
# Fit a normal distribution to the data:
mu, std = norm.fit(data)
# Plot the histogram.
plt.hist(data, bins=25, density=True, alpha=0.6, color='g')
# Plot the PDF.
xmin, xmax = plt.xlim()
x = np.linspace(xmin, xmax, 100)
p = norm.pdf(x, mu, std)
plt.plot(x, p, 'k', linewidth=2)
title = "Fit results: mu = %.2f, std = %.2f" % (mu, std)
plt.title(title)
plt.show()
import seaborn as sns
from scipy.stats import norm
data = norm.rvs(5,0.4,size=1000) # you can use a pandas series or a list if you want
sns.distplot(data)
plt.show()
import numpy as np
import seaborn as sns
from scipy.stats import norm
# Generate simulated data
n_samples = 100
rng = np.random.RandomState(0)
data = rng.standard_normal(n_samples)
# Fit Gaussian distribution and plot
sns.distplot(data, fit=norm, kde=False)