Error in finite difference approximation of derivative

Compute derivative of $$ f(x) = \sin(x) $$ at $x=2\pi$ using finite difference $$ \frac{f(x+h) - f(x)}{h} $$ for $h=10^{-1},10^{-2},\ldots,10^{-14}$.

In [24]:
from numpy import sin,arange,zeros,pi,abs
from matplotlib.pyplot import loglog,xlabel,ylabel
In [34]:
def f(x):
    return sin(x)
In [35]:
h = 10.0**arange(-1,-15,-1)
df= zeros(len(h))
x = 2.0*pi
f0= f(x)
for i in range(len(h)):
    f1 = f(x+h[i])
    df[i] = (f1 - f0)/h[i]
loglog(h,abs(df-1.0),'o-')
xlabel('h')
ylabel('Error in derivative')
Out[35]:
<matplotlib.text.Text at 0x1108a8f50>