I created a histogram plot based on my datasets. I would like to create a Weibull fit for this histogram. I used scipy and the stats.weibull function, but unfortunately, it does not work.
Do you have an idea of how to use the stats.weibull in this case?
Here is the code:
import pandas as pd
import matplotlib.pyplot as plt
import numpy as np
import scipy.stats as stats
data = 'Figures/Histogram/Histogram.xlsx'
hist= pd.read_excel('Histogram/Histogram.xlsx')
# x= hist['DeltaT_value']
x= hist['DeltaT_-250_2017']
X=x[(x>0)]
plt.figure(figsize=(15,4))
plt.hist(X, bins= np.arange (0,1500,25), color='#0504aa', edgecolor ='red', rwidth= 0.8)
plt.ylabel('Number of EL')
plt.xlabel('Delta T (years CE) between EL')
plt.xlim(0, 401)
plt.xticks(np.arange(0,401,25))
plt.yticks(np.arange(0,2.2,1))`
# Weibull
####
shape, loc, scale = stats.weibull_min.fit(X)
x = np.linspace(stats.weibull_min.ppf(0.01, shape, loc=loc, scale=scale), stats.weibull_min.ppf(0.99, shape, loc=loc, scale=scale), 100)
plt.plot(x, stats.weibull_min.pdf(x, shape, loc=loc, scale=scale), 'r-', lw=5, alpha=0.6, label='weibull')
I tried this:
shape, loc, scale = stats.weibull_min.fit(X)
x = np.linspace(stats.weibull_min.ppf(0.01, shape, loc=loc, scale=scale), stats.weibull_min.ppf(0.99, shape, loc=loc, scale=scale), 100)
plt.plot(x, stats.weibull_min.pdf(x, shape, loc=loc, scale=scale), 'r-', lw=5, alpha=0.6, label='weibull')
Unfortunately, it seems another graph is created on top of the histogram instead of a fit.


After working on it for a little while, I found a solution:
Robert Dodier's comments on my original post are very interesting and I will try to see how I can use a "log likelihood function" on the original dataset rather than a fit on the histogram. This is the first time I will use a log likelihood function. If anyone has some advice, I would gladly take it.
Thanks.