Using the following code, I can plot a histogram of my data and the fitting curve to the histogram.
mybins = len(data)//20
fig, (ax) = plt.subplots(1,1, figsize=(5, 3))
(mu,sigma) = scipy.stats.norm.fit(data)
n,bins,patches=ax.hist(data, bins=mybins, density=True, color='green', histtype='stepfilled', linewidth=1)
ax.axvline(x=data.mean(), color='green', linestyle='dashed', linewidth=3)
y = scipy.stats.norm.pdf(bins, mu, sigma)
ax.plot(bins,y,'r--',color='green', linewidth=3)
ax.set_xlim(0.5,1.1)
This is the output which is correct fot the histogram and its vertical line of mean.
But, the fitting curve is a normal fitting against the mean.
I need help to implement a Weibull fit which should be resulting in a skewed fitting curve according to the data distribution.
Tried using the following from this:
shape, loc, scale = weibull_min.fit(data, floc=0)
plt.plot(data, stats.exponweib.pdf(data, *stats.exponweib.fit(data, 1, 1, scale=scale, loc=loc)))
plt.hist(data, label='PR', density=True, bins=len(data)//15, color = 'orangered')
plt.axvline(x=data.mean(), color='black', linestyle='dashed', linewidth=3)
plt.show()
Edit:
Another try with sorted data:
fig, (ax) = plt.subplots(1,1, figsize=(5, 3))
ax.hist(data, bins=len(data)//15, color = 'orangered')
shape, loc, scale = weibull_min.fit(data, floc=0)
plt.plot(data, stats.exponweib.pdf(data, *stats.exponweib.fit(data, 1, 1, scale=scale, loc=loc)))
plt.show()
The result is now much better, but still not yet what it should be, i.e. the fit curve doesn't fit the 'size' of histogram.
My data can be downloaded from here.
Thanks for any help.