python - Matplotlib Draw Spline from 3 points -


i draw spline follow post: matplotlib draw spline multiple points

but when draw spline 3 points

from __future__ import division import matplotlib.pyplot plt import numpy np scipy import interpolate   nodes = np.array( [ [1, 2], [6, 15], [10, 6] ] )  x = nodes[:,0] y = nodes[:,1]  tck,u     = interpolate.splprep( [x,y] ,s = 0 ) xnew,ynew = interpolate.splev( np.linspace( 0, 1, 100 ), tck,der = 0)  plt.plot( x,y,'o' , xnew ,ynew ) plt.legend( [ 'data' , 'spline'] ) plt.axis( [ x.min() - 1 , x.max() + 1 , y.min() - 1 , y.max() + 2 ] ) plt.show() 

i error

raise typeerror('m > k must hold') typeerror: m > k must hold 

so, me draw spline 3 points :(

the number of points (m) must greater degree of spline (k). according documentation, default degree k = 3. since have 3 points, degree needs set 2 changing following line:

tck,u = interpolate.splprep( [x,y], k = 2) 

3 point spline


Comments

Popular posts from this blog

php - failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request -

java - How to filter a backspace keyboard input -

java - Show Soft Keyboard when EditText Appears -