title: Get derivative of data in python
body: <p>I write a program to get derivative. InterpolatedUnivariateSpline is used for calculating f(x+h). The red line is derivative of cosine, the green line is cosine consine, the blue line is -sine function. The red and blue line are matched. It works well in the following. </p>
  
  <p><img src="https://i.stack.imgur.com/CpKGg.png" alt="Result"></p>
  
  <pre><code>from scipy.interpolate import InterpolatedUnivariateSpline
  import numpy as np 
  import matplotlib.pyplot as plt
  
  pi = np.pi
  x = np.arange(0,5*pi,0.2*pi)
  y = np.cos(x) 
  f2 = InterpolatedUnivariateSpline(x, y)
  #Get dervative
  der = []
  for i in range(len(y)):
  
      h = 1e-4
      der.append( ( f2(x[i]+h)-f2(x[i]-h) )/(2*h) )
  der = np.array(der)   
  
  plt.plot(x, der, 'r', x, y, 'g', x, -np.sin(x),'b')
  plt.show()
  </code></pre>
  
  <p>But I encounter some problem. In my project, my variable x(frequency) vary from 10^7 to 2.2812375*10^9, its step is 22487500,so I change array x.
  As a result, I get the following result. </p>
  
  <p><img src="https://i.stack.imgur.com/1jogB.png" alt="Result2"></p>
  
  <p>The derivative is a line and almost close to 0, It is not -sine function. How do I solve this?</p>