I have a graph with me that is logarithmic on both axes. I have a pyplot function loglogto do this. It also gives me a logarithmic scale on both axes.
Now, using numpy, I map a straight line to the many points that I have. However, when I draw this line on the plot, I cannot get a straight line. I get a curved line.

The blue line is supposedly a "straight line". This is not straightforward. I want to put this straight line to the curve drawn by red dots
Here is the code I use to plot the points:
import numpy
from matplotlib import pyplot as plt
import math
fp=open("word-rank.txt","r")
a=[]
b=[]
for line in fp:
string=line.strip().split()
a.append(float(string[0]))
b.append(float(string[1]))
coefficients=numpy.polyfit(b,a,1)
polynomial=numpy.poly1d(coefficients)
ys=polynomial(b)
print polynomial
plt.loglog(b,a,'ro')
plt.plot(b,ys)
plt.xlabel("Log (Rank of frequency)")
plt.ylabel("Log (Frequency)")
plt.title("Frequency vs frequency rank for words")
plt.show()
source
share