威布尔拟合直方图不是一条平滑的线
Weibull fit to histogram is not a smooth line
我使用以下代码对我的数据进行威布尔分布拟合:
# -- 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
您正在使用 "stats.exponweib.pdf(bins",因此绘制的线段数等于 bin 数。如果您有五个直方图 bin,则绘制的线将有五个线段并且会显得非常不平滑。相反,如果您使用类似的东西:
xplot = numpy.linspace(min(bins), max(bins), 100)
stats.exponweib.pdf(xplot
这样绘制出来的线就有100条线段,外观上会明显更平滑
我使用以下代码对我的数据进行威布尔分布拟合:
# -- 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
您正在使用 "stats.exponweib.pdf(bins",因此绘制的线段数等于 bin 数。如果您有五个直方图 bin,则绘制的线将有五个线段并且会显得非常不平滑。相反,如果您使用类似的东西:
xplot = numpy.linspace(min(bins), max(bins), 100)
stats.exponweib.pdf(xplot
这样绘制出来的线就有100条线段,外观上会明显更平滑