我画了Spline
关注帖子:Matplotlib draw Spline from multiple points
但是当我从3分中画出Spline
时
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()
我收到错误
raise TypeError('m > k must hold')
TypeError: m > k must hold
所以,帮助我从3点画出Spline :(
答案 0 :(得分:6)
点数(m)必须大于样条曲线(k)的数量。根据{{3}},默认度数为k = 3.由于您有三个点,因此需要通过更改以下行将度数设置为2:
tck,u = interpolate.splprep( [x,y], k = 2)