我正在尝试将具有特定 a 和 b 参数的截断正态分布覆盖在从相同分布生成的样本直方图上。
import numpy as np
import matplotlib.pyplot as plt
import scipy.stats as stats
import matplotlib.mlab as mlab
from IPython.display import Math, Latex
# for displaying images
from IPython.core.display import Image
# import seaborn
import seaborn as sns
# settings for seaborn plotting style
sns.set()
# settings for seaborn plot sizes
sns.set(rc={'figure.figsize':(5,5)})
tempdist=[]
samples=100
for k in range(1,samples):
#Probability
#Storage temp as truncated normal
#temperature as normal mean 55 with 5F variation
storagetempfarenht = 57 #55
storagetempkelvin = (storagetempfarenht + 459.67) * (5.0/9.0)
highesttemp=storagetempfarenht + 5
lowesttemp= storagetempfarenht -5
sigma = ((highesttemp + 459.67) * (5.0/9.0)) - storagetempkelvin
mu, sigma = storagetempkelvin, sigma
lower, upper = mu-2*sigma , mu+2*sigma
a=(lower - mu) / sigma
b=(upper - mu) / sigma
temp =stats.truncnorm.rvs(a, b, loc=mu, scale=sigma, size=1)
mean, var, skew, kurt = stats.truncnorm.stats(a, b, moments='mvsk')
tempdist.append(temp)
#Theses are the randomly generated values
tempdist=np.array(tempdist)
x = range(250,350)
ax = sns.distplot(tempdist,
bins=500,
kde=True,
color='r',
fit=stats.truncnorm,
hist_kws={"linewidth": 15,'alpha':1})
ax.set(xlabel='Trunc Normal Distribution', ylabel='Frequency')