Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

best fit line python log log scale

fig=plt.figure()
ax = fig.add_subplot(111)

z=np.arange(1, len(x)+1) #start at 1, to avoid error from log(0)

logA = np.log(z) #no need for list comprehension since all z values >= 1
logB = np.log(y)

m, c = np.polyfit(logA, logB, 1, w=np.sqrt(y)) # fit log(y) = m*log(x) + c
y_fit = np.exp(m*logA + c) # calculate the fitted values of y 

plt.plot(z, y, color = 'r')
plt.plot(z, y_fit, ':')

ax.set_yscale('symlog')
ax.set_xscale('symlog')
#slope, intercept = np.polyfit(logA, logB, 1)
plt.xlabel("Pre_referer")
plt.ylabel("Popularity")
ax.set_title('Pre Referral URL Popularity distribution')
plt.show()
Comment

PREVIOUS NEXT
Code Example
Python :: python program to print inverted star pattern 
Python :: concat dataframe pandas 
Python :: python list of dictionaries 
Python :: python lambda function if else 
Python :: check for string in list py 
Python :: terminal output redirect to a file 
Python :: make a new environment conda 
Python :: how to hide ticks marks in matplotlib 
Python :: get current url with parameters url django 
Python :: python string remove whitespace 
Python :: install fastapi 
Python :: python pandas return column name of a specific column 
Python :: flask bootstrap 
Python :: tuple index in python 
Python :: datetime decreasing date python 
Python :: creating class and object in python 
Python :: how to run loops 3 times in python 
Python :: Dictionary convert 2 lists into a dictionary, use zip() 
Python :: how to set the value of a variable null in python 
Python :: Swap first and last list elements 
Python :: python assert is datetime 
Python :: nested loop 
Python :: gradient descent python 
Python :: Python random integer number between min, max 
Python :: python datetime minus datetime 
Python :: drop 0 in np array 
Python :: Reason: Worker failed to boot 
Python :: series astype 
Python :: django forms error customize 
Python :: python program to find the sum of fibonacci series 
ADD CONTENT
Topic
Content
Source link
Name
7+2 =