title: Savitzky-Golay filtering giving incorrect derivative in 1D
body: <p>I have an x and y dataset, with x as the independent variable and y as the dependent variable. </p>
  
  <blockquote>
    <p>y=2x</p>
  </blockquote>
  
  <p><br />
  I add some noise to 'y' and apply the scipy Savitzky Golay filter. When I attempt to get the first derivative of y, I get the derivative as zero.
  I understand this is because of the filter takes only 'y' as the input. I would want to have a filter that considers both x and y, and also provide me with a derivative value.</p>
  
  <p>Here I show my implementation with the plots indicating incorrect data. </p>
  
  <pre><code>import numpy as np
  from scipy import signal
  import matplotlib.pyplot as plt
  
  # create some sample twoD data
  x = np.linspace(-3,3,100)
  y = 2*x
  y = y + np.random.normal(0, 0.2, y.shape)
  
  # filter it
  Zn = signal.savgol_filter(y, window_length=29, polyorder=4, deriv=0)
  Zf = signal.savgol_filter(y, window_length=29, polyorder=4, deriv=1)
  # do some plotting
  plt.plot(x,y, label = 'Input')
  plt.plot(x,Zn, label= 'Savitzky-Golay filtered')
  plt.plot(x,Zf, label= 'Savitzky-Golay filtered - 1st derivative')
  plt.legend()
  plt.show()
  </code></pre>
  
  <p>Result:<a href="https://i.stack.imgur.com/bLbjs.png" rel="noreferrer"><img src="https://i.stack.imgur.com/bLbjs.png" alt="enter image description here"></a></p>
  
  <p>The derivative result:
  dy/dx = 2. 
  <br />
  I need the Savitzky-Golay filter to provide me this result. Please help me with a python implementation that considers two variables.</p>