1fig=plt.figure()
2ax = fig.add_subplot(111)
3
4z=np.arange(1, len(x)+1) #start at 1, to avoid error from log(0)
5
6logA = np.log(z) #no need for list comprehension since all z values >= 1
7logB = np.log(y)
8
9m, c = np.polyfit(logA, logB, 1, w=np.sqrt(y)) # fit log(y) = m*log(x) + c
10y_fit = np.exp(m*logA + c) # calculate the fitted values of y
11
12plt.plot(z, y, color = 'r')
13plt.plot(z, y_fit, ':')
14
15ax.set_yscale('symlog')
16ax.set_xscale('symlog')
17#slope, intercept = np.polyfit(logA, logB, 1)
18plt.xlabel("Pre_referer")
19plt.ylabel("Popularity")
20ax.set_title('Pre Referral URL Popularity distribution')
21plt.show()