title: Derivatives of a spline: `scipy splev`
body: <p>I'm trying to find derivatives of a spline at several points using <code>splev</code> in <code>scipy</code>. For example:</p>
  
  <pre><code>import numpy as np
  from scipy.interpolate import splprep, splev
  import matplotlib.pyplot as plt
  
  # function to normalize each row
  def normalized(a, axis=-1, order=2):
      l2 = np.atleast_1d(np.linalg.norm(a, order, axis))
      l2[l2==0] = 1
      return a / np.expand_dims(l2, axis)
  
  # points and spline
  pts = np.array([[0,0],[1,1],[2,np.sqrt(2)],[4,2],[9,3]])
  tck, u = splprep(pts.T, u=None, k=3, s=0.0, per=0)
  
  # compute new points and derivatives
  u_new = np.linspace(u.min(), u.max(), 5*u.shape[0])
  x_new, y_new = splev(u_new, tck, der=0)
  xp_num, yp_num = splev(pts, tck, der=1) # numerical derivatices
  xp_the, yp_the= pts[1:,0], 0.5/np.sqrt(pts[1:,0]) # analytical derivatives
  R = normalized(yp_num/xp_num)
  X,Y = pts[1:,0], pts[1:,1]
  U,V = X + R[1:,0], Y+R[1:,1]
  </code></pre>
  
  <p>I'd like to plot the tangents at the given point:</p>
  
  <pre><code>plt.plot(x_new,y_new,'-b')
  plt.plot(pts[:,0],pts[:,1],'--ro')
  plt.quiver(X,Y,U,V, angles='xy', scale_units='xy')
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/SkTiz.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/SkTiz.png" alt="enter image description here"></a></p>
  
  <p>I think these tangent lines are wrong. My understanding was that <code>xp_num</code> and <code>yp_num</code> are numerical derivatives of the spline with respect to <code>x</code> and <code>y</code>. So to find <code>dy/dx</code>, I should simply divide them. Is this correct?</p>
  
  <p>Eventually, I'd like to find tangents of a curve like <a href="https://stackoverflow.com/questions/31464345/fitting-a-closed-curve-to-a-set-of-points">this</a></p>