How to fit to a log scale

Viewed 9879

I have the following points

0 4194304
1 497420
2 76230
3 17220
4 3595
5 1697
6 491
7 184
8 54
9 15
10 4
11 4
12 1
13 1
14 1
15 1
16 1
17 1
18 1
19 1
20 1
21 1

If I plot them with a log scale on the y-axis they look roughly linear. How can I fit a straight line to this log scale so I can fit the data?

My current code is very crude. For each x,y pair I do.

xcoords.append(x)
ycoords.append(math.log(y))

And then at the end I do

plt.plot(xcoords,ycoords)
plt.show()
3 Answers
Related