Issue
Here is my code:
import matplotlib.pyplot as plt
plt.loglog(length,time,'--')
where length and time are lists.
How do I find the linear fit slope of this graph?
Solution
If you have matplotlib then you must also have numpy installed since it is a dependency. Therefore, you could use numpy.polyfit to find the slope:
import matplotlib.pyplot as plt
import numpy as np
length = np.random.random(10)
length.sort()
time = np.random.random(10)
time.sort()
slope, intercept = np.polyfit(np.log(length), np.log(time), 1)
print(slope)
plt.loglog(length, time, '--')
plt.show()
Answered By - unutbu
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.