curve fitting on log scale python code example
Example 1: numpy exponential curve fit
>>> def func(x, a, b, c):
... return a * np.exp(-b * x) + c
Example 2: numpy exponential curve fit
>>> import matplotlib.pyplot as plt
>>> from scipy.optimize import curve_fit
Example 3: logarithmic scale fitting python
fig=plt.figure()
ax = fig.add_subplot(111)
z=np.arange(1, len(x)+1)
logA = np.log(z)
logB = np.log(y)
m, c = np.polyfit(logA, logB, 1, w=np.sqrt(y))
y_fit = np.exp(m*logA + c)
plt.plot(z, y, color = 'r')
plt.plot(z, y_fit, ':')
ax.set_yscale('symlog')
ax.set_xscale('symlog')
plt.xlabel("Pre_referer")
plt.ylabel("Popularity")
ax.set_title('Pre Referral URL Popularity distribution')
plt.show()