gpt4 book ai didi

python - 对直方图中绘制的给定数据标准化威 bool 分布

转载 作者:行者123 更新时间:2023-12-01 08:23:46 29 4
gpt4 key购买 nike

我正在尝试复制此图 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()

(而不是之前代码中的最后三行,没有成功)

最佳答案

不完全确定 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

关于python - 对直方图中绘制的给定数据标准化威 bool 分布,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54435652/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com