Weibull拟合直方图不是一条平滑线

问题描述 投票:0回答:1

我使用以下代码将Weibull分布适合我的数据:

# -- set up the figure and axis
fig, ax = plt.subplots(figsize=(10, 7))

# Set bins:
bins = np.arange(0, 40+0.5, 1)

# -- make a histogram 
ax.hist(af_farm_w_speed, bins=bins, density=True, alpha = 1, align='left', zorder=0, rwidth=0.7, color='grey')

ax.set_xlabel("Wind Speed [knots]", fontsize=15)
ax.set_ylabel("Frequency [%]", fontsize=15)
ax.set_title('Wind Speed Distribution and Weibull fit', fontsize=18)
(scale, a, shape, c) = stats.exponweib.fit(af_farm_w_speed, f0=1, floc=0)
ax.plot(bins, stats.exponweib.pdf(bins, *stats.exponweib.fit(af_farm_w_speed, f0=1, floc=0)), zorder=1, color = "black", linewidth=1.6, label="Post-Farm Weibull Fit (a={:.4g}, c={:.5g})".format(a, c))
ax.legend()

但是,如输出所示,我的拟合度不是一条平滑的线。有人对如何解决这个问题有想法吗?enter image description here

python histogram curve-fitting weibull
1个回答
0
投票

您正在使用“ stats.exponweib.pdf(bins”,因此要绘制的段数等于bin的数量。如果您有五个直方图bin,则绘制的线将具有五个段,并且看起来非常不均匀-如果您使用类似的方法:

xplot = numpy.linspace(min(bins), max(bins), 100)
stats.exponweib.pdf(xplot

然后绘制的线将具有100个线段,并且外观上将明显更平滑。

© www.soinside.com 2019 - 2024. All rights reserved.