I'm fitting a lognormal pdf to some binned data, but my curve doesn't quite match the data, see image below. My code is:
import numpy as np
import matplotlib.pyplot as plt
from scipy.stats import lognorm
data = genfromtxt('data.txt')
data = np.sort(data)
# plot histogram in log space
ax.hist(data, bins=np.logspace(0,5,200),normed=1)
ax.set_xscale("log")
shape,loc,scale = lognorm.fit(data)
print shape, loc, scale
pdf = sp.stats.lognorm.pdf(data, shape, loc, scale)
ax.plot(data,pdf)
plt.show()
This is what it looks like:
Do I need to somehow provide the fit with sensible guesses for shape, loc and scale?
Thanks!
data
(especially because we don't know the contents). Normally you would use np.linspace() to generate some kind of grid like in the docs. (4) And just to be sure matplotlib is not introducing trouble: i would just try it without logscale (analysis-only, without much hope)