I draw Spline follow post: Matplotlib draw Spline from multiple points
But when I draw Spline from 3 points
from __future__ import division
import matplotlib.pyplot as plt
import numpy as np
from 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 get error
raise TypeError('m > k must hold')
TypeError: m > k must hold
So, help me draw Spline from 3 points :(
The number of points (m) must be greater than the degree of the spline (k). According to the documentation, the default degree is k = 3. Since you have three points, the degree needs to be set to 2 by changing the following line:
tck,u = interpolate.splprep( [x,y], k = 2)

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With