为什么在绘制分布时我会得到多条线?

2024-09-28 17:04:07 发布

您现在位置:Python中文网/ 问答频道 /正文

我有一些数据,我正试图拟合正态分布和对数正态分布df.head(10)

year    Q
1885     7241
1886     9164
1887     7407
1888     6870
1889     9855
1890    11887
1891     8827
1892     7546
1893     8498
1894    16757
Name: Q, dtype: int64

拟合分布

from scipy import stats
mean = df['Q'].mean()
std = df['Q'].std()
print(mean, std)
6636.172413793103 3130.779541854595

#Fitting
distnormal = stats.norm.pdf(df['Q'], loc = mean, scale = std)
distlognormal = stats.pearson3.pdf(df['Q'], skew = 1, loc = mean, scale = std)

# Plotting
df.hist(bins=10, edgecolor='#4aaaaa', density = True)
plt.plot(df['Q'], distnormal, color = 'red')
plt.plot(df['Q'], distlognormal, color = 'blue')
plt.show()

但是我得到了一个像这样的情节有太多的线。我怎样才能正确地适应分布? enter image description here


Tags: 数据dfpdfplotstatspltmeanloc