[SciPy-user] Interpolation using splines

Stefan van der Walt stefan at sun.ac.za
Tue Sep 26 09:21:05 CDT 2006


On Tue, Sep 26, 2006 at 02:27:42PM +0200, Ewald Zietsman wrote:
> Hi all,
> 
> I'm trying to fit a cubic spline to a data set. I can't seem to get the
> functions in scipy.interpolate (splrep and splev) to work correctly ( I'm
> probably being stupid).
> 
> When I do the following,
> 
> #! /usr/bin/python
> from scipy import interpolate
> from pylab import *
> x = arange(0.0,2.0*pi+pi/4.0,2.0*pi/8.0)
> y = sin(x)
> tck = interpolate.splrep(x,y,s=0.0)
> xnew = arange(0.0,2.0*pi+pi/4.0,pi/50.0)
> ynew = interpolate.splev(xnew,tck,der=0.0)
> 
> plot(x,y,'x')
> plot(xnew,ynew,'r-')
> show()
> 
> 
> I should get a plot showing a sin curve made of blue x's and a smooth red line
> which is the spline. However, the spline seems to be zero except for one place
> where it spikes.
> I'm using scipy 0.5.0 and matplotlib 0.87.3 with python 2.4.3 on Fedora Core 5.
> Any help on this will be appreciated.

Your code gives the correct result on my machine:

numpy 1.0.dev3204
scipy 0.5.2.dev2205

Regards
Stéfan


More information about the SciPy-user mailing list