| | import numpy
import scipy
import matplotlib.pyplot as plt
dt = 0.05
real_t = numpy.array( [0., 1., 2., 2.+dt, 3.+dt, 4.+dt] )
assumed_t = numpy.array( [0., 1., 2., 3., 4., 5.] )
x = numpy.sin( real_t )
y = numpy.cos( real_t )
plt.plot(x, y, 'o', label='input points')
plt.plot(numpy.sin( numpy.linspace( 0., 4.+dt, 100 ) ),
numpy.cos( numpy.linspace( 0., 4.+dt, 100 ) ), '--', label='cirle')
t_test_plonts = numpy.linspace( min(assumed_t), max(assumed_t), 200 )
for alg, name in zip([scipy.interpolate.CubicSpline, scipy.interpolate.KroghInterpolator,
scipy.interpolate.PchipInterpolator, scipy.interpolate.Akima1DInterpolator],
["Cubic", "Krogh", "Pchip", "Akima1D"]):
x_spline = alg(assumed_t, x)(t_test_plonts)
y_spline = alg(assumed_t, y)(t_test_plonts)
plt.plot(x_spline, y_spline, '-', label=name)
plt.xlim([-1.2, 1.2])
plt.ylim([-1.2, 1.2])
plt.legend()
plt.show()
|