I'm trying to plot a gamma distribution and I expect it to be normalized, but somehow, the values always diverge too much and I'm not getting the expected result.
My code so far looks like this:
from scipy.stats import gamma
a,loc,scale = gamma.fit(data)
x =np.linspace(gamma.ppf(0.1,a),gamma.ppf(0.99,a), data.size)
y = gamma.pdf(x,a,scale=scale,loc=loc)
plt.plot(x,y , color='#606060')
There are values very close to 0 in my data, which could be the main cause of the divergency. But even when I normalize the y
values, I don't get what I expected. When I plot the gamma distribution, it diverges completely and looks like this:
For context: I'm already plotting an histogram and the normal distribution of my data, and they look fine. I expected my final plot to look something like this: Desired plot
samples = stats.gamma.rvs(alpha, loc=loc, scale=scale, size=10000)
plt.hist(samples)
does this look like you expect it?