Interpolation using splines
![](https://secure.gravatar.com/avatar/70970821c904913b453a3a2b9d14658f.jpg?s=120&d=mm&r=g)
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. -Ewald
![](https://secure.gravatar.com/avatar/af6c39d6943bd4b0e1fde23161e7bb8c.jpg?s=120&d=mm&r=g)
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
![](https://secure.gravatar.com/avatar/ec519a942d15ab14cd207c3c6adf57c3.jpg?s=120&d=mm&r=g)
Works for me using scipy 0.5.1.dev2185 on OS X. Michael. In article <be152e7d0609260527m5f178d2end1257e2216b49b8f@mail.gmail.com>, "Ewald Zietsman" <ewald.zietsman@gmail.com> wrote: ...
#! /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...
![](https://secure.gravatar.com/avatar/ab7e74f2443b81e5175638d72be65e07.jpg?s=120&d=mm&r=g)
On 26/09/06, Ewald Zietsman <ewald.zietsman@gmail.com> 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).
Your code, cut-n-pasted, works fine for me, using scipy-0.5.2 and numpy-1.0b5. Are you on a 64-bit platform? There was a bug (although these were not its symptoms). A. M. Archibald
participants (4)
-
A. M. Archibald
-
Ewald Zietsman
-
Michael McNeil Forbes
-
Stefan van der Walt