I used the following code to fit a Weibull distribution to my data:
# -- 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()
However, as shown on the output, my fit is not a smooth line. Would any one have an idea on how to fix that?enter image description here
You are using "stats.exponweib.pdf(bins", so the number of segments being plotted is equal to the number of bins. If you had five histogram bins, the plotted line would have five segments and would appear very un-smooth. If instead you use something like:
xplot = numpy.linspace(min(bins), max(bins), 100)
stats.exponweib.pdf(xplot
then the plotted line will have 100 segments, and will be visibly smoother in appearance.