#p100下半部分
#4.1.2scipy
#例子2 interpolate.splev 函数 利用B样条和它的导数进行插值,interpolate.splev课展现二维曲线插值
import numpy as np
import matplotlib.pyplot as plt
import scipy as sp
from scipy.interpolate import splprep #增加该行
t=np.arange(0,2.5,.10)#0到2.5之间生成一个一维数组,差值0.10
x=np.sin(2*np.pi*t)
y=np.cos(2*np.pi*t)
tcktuples,uarray=sp.interpolate.splprep([x,y],s=0)
unew=np.arange(0,1.01,0.01)
splinevalues=sp.interpolate.splev(unew,tcktuples)
plt.figure(figsize=(10,10))
#plt.plot(x,y,'x',splinevalues[0],splinevalues[1],np.sin(2*np.pi*unew),np.cos(2*np.pi*unew),x,y,'b')
plt.plot(x,y,'x')#linear#圆--离散点
#plt.plot(splinevalues[0],splinevalues[1])#圆
#plt.plot(np.sin(2*np.pi*unew),np.cos(2*np.pi*unew))#圆
#plt.plot(np.sin(2*np.pi*unew))#线
#plt.plot(np.cos(2*np.pi*unew))#线
#plt.plot(x,y,'b')#多边形
plt.legend(['Linear','Cubic Spline','True'])
plt.axis([-1.25,1.25,-1.25,1.25])
plt.title('Parametric Spline Interpolation Curve')
plt.show()
#4.1.2scipy
#例子2 interpolate.splev 函数 利用B样条和它的导数进行插值,interpolate.splev课展现二维曲线插值
import numpy as np
import matplotlib.pyplot as plt
import scipy as sp
from scipy.interpolate import splprep #增加该行
t=np.arange(0,2.5,.10)#0到2.5之间生成一个一维数组,差值0.10
x=np.sin(2*np.pi*t)
y=np.cos(2*np.pi*t)
tcktuples,uarray=sp.interpolate.splprep([x,y],s=0)
unew=np.arange(0,1.01,0.01)
splinevalues=sp.interpolate.splev(unew,tcktuples)
plt.figure(figsize=(10,10))
#plt.plot(x,y,'x',splinevalues[0],splinevalues[1],np.sin(2*np.pi*unew),np.cos(2*np.pi*unew),x,y,'b')
plt.plot(x,y,'x')#linear#圆--离散点
#plt.plot(splinevalues[0],splinevalues[1])#圆
#plt.plot(np.sin(2*np.pi*unew),np.cos(2*np.pi*unew))#圆
#plt.plot(np.sin(2*np.pi*unew))#线
#plt.plot(np.cos(2*np.pi*unew))#线
#plt.plot(x,y,'b')#多边形
plt.legend(['Linear','Cubic Spline','True'])
plt.axis([-1.25,1.25,-1.25,1.25])
plt.title('Parametric Spline Interpolation Curve')
plt.show()