对直方图中绘制的给定数据进行标准化威布尔分布

时间:2019-01-30 07:52:34

标签: python matplotlib seaborn

尝试复制此图     https://wind-data.ch/tools/weibull.php 我处理的代码是:-

import matplotlib.pyplot as plt
import numpy as np
import matplotlib.mlab as mlab
import math
import scipy.stats as stats
from scipy.stats import dweibull
import pandas as pd
import seaborn as sns

frequency =     [2.75,7.80,11.64,13.79,14.20,13.15,
11.14,8.72,6.34,4.30,2.73,1.62,0.91,0.48,
0.24,0.11,0.05,0.02,0.01,0.00]
k = 2.00
lambd =6.00
mu = 0
dist = dweibull(k,mu,lambd)
x = np.linspace(-20,20, 1000)

sns.set_style('darkgrid')
sns.distplot(frequency, fit=stats.dist.pdf(x), kde=False)
sns.show()

我认为我可能有一些逻辑错误, 在纠正它方面需要帮助(这是全新的东西)

最初将matplotlib尝试为:

plt.plot(x, 210 * dist.pdf(x),label=r'$k=%.1f,\ \ lambd=%i$' % (k,   lambd))
plt.xlim(0, 21)
plt.ylim(0, 15.0)
plt.hist(frequency,bins ='auto')
plt.show()

(不是先前代码中的最后三行,没有解决)

1 个答案:

答案 0 :(得分:0)

不能完全确定iiuc,但这是我的第一种方法:

import matplotlib.pyplot as plt
import numpy as np

def wd(x, k, A):
    return k/A*(x/A)**(k-1) * np.exp(-(x/A)**k)

frequency = [2.75, 7.80, 11.64, 13.79, 14.20, 13.15, 11.14, 8.72, 6.34, 4.30, 2.73, 1.62, 0.91, 0.48, 0.24, 0.11, 0.05, 0.02, 0.01, 0.00]
k = 2.00
lambd = 6.00

plt.figure(figsize=(8, 4))
plt.step(range(len(frequency)), frequency, where='post')
plt.plot(wd(np.arange(len(frequency)), k, lambd)*100)

创建

enter image description here