Python 直方图的威布尔拟合不是一条平滑的线

Python 直方图的威布尔拟合不是一条平滑的线,python,histogram,curve-fitting,weibull,Python,Histogram,Curve Fitting,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, rw

我使用以下代码将威布尔分布拟合到我的数据中:

# -- 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()
但是,如输出所示,我的拟合不是一条平滑的线。有人知道如何解决这个问题吗?

您使用的是“stats.exponweib.pdf(bin)”,因此绘制的线段数等于bin数。如果您有五个柱状图bin,则绘制的直线将有五个线段,并且看起来非常不平滑。如果改用以下方式:

xplot = numpy.linspace(min(bins), max(bins), 100)
stats.exponweib.pdf(xplot
然后,绘制的线将有100个线段,并且外观将明显更平滑