【问题标题】:Weibull fit to histogram is not a smooth lineWeibull 拟合直方图不是一条平滑线
【发布时间】:2020-02-28 07:05:59
【问题描述】:

我使用以下代码将 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】:

    您正在使用“stats.exponweib.pdf(bins”,因此绘制的段数等于 bin 的数量。如果您有五个直方图 bin,则绘制的线将有五个段,并且看起来很不-smooth。如果你使用类似的东西:

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

    那么绘制的线将有 100 段,并且在外观上会明显更平滑。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-02-17
      • 2023-01-17
      • 1970-01-01
      • 2017-01-02
      • 1970-01-01
      • 2019-10-18
      相关资源
      最近更新 更多