Interpolation Spline in python?

Asked

Viewed 468 times

1

What is the best method to interpolate Spline second-order Python? I’ve used interp1d, but not quite what I intend.

Example of what is intended.

from scipy.interpolate import interp1d 
import matplotlib.pyplot as plt 

x = [5,6,7,8,9,10,11]
y = [2,9,6,3,4,20,6]


xx = [1,2,3,4,5,6,7,8,9,10,11,12] 
f = interp1d(x, y, kind='quadratic') 
g = f(xx)

I intend to calculate the yy, but I get the following error:

Valueerror: A value in x_new is Below the Interpolation range.

I would like to get to python something similar to the following in Matlab

x=[5,6,7,8,9,10,11]
y=[2,9,6,3,4,20,6]
xx=[1,2,3,4,5,6,7,8,9,10,11,12]
yy = spline(x,y,xx);
plot(x,y,'o',xx,yy)
  • The code I executed is in the published issue.

  • Good morning, the value xx is above the interpolation range, if you leave from 5 to 11, will run, but do not know what your intention to use this range.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.