Ask Your Question

interpolated 2D plot

asked 2011-11-14 17:10:36 +0200

v_2e gravatar image

Hello! Is there a way to create a plot from a list of data using some kind of non-linear interpolation (e.g. splines) between the data points?


edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2011-11-14 17:24:59 +0200

DSM gravatar image

Sure, there are a couple of ways. Here are two:

import numpy
from scipy import interpolate

data = [(x, sin(x)**2+(x % 2.7)**3) for x in numpy.linspace(0, 5, 20)]

# separate data into x and y components
xx,yy = zip(*data)

# build spline in two ways..
scipy_spline = interpolate.InterpolatedUnivariateSpline(xx, yy)

gsl_spline = spline(data)

p = list_plot(data, color="green")
p += plot(scipy_spline, (0, 5), color="red")
p += plot(gsl_spline, (0, 5), linestyle='--', color="blue")

Note that if you build the spaces yourself and use the built-in spline object you wouldn't need to import anything.

image description

edit flag offensive delete link more


Thanks a lot! I guess, "gsl_spline = spline(data)" is exactly what I need. :)

v_2e gravatar imagev_2e ( 2011-11-24 10:22:09 +0200 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools


Asked: 2011-11-14 17:10:36 +0200

Seen: 1,061 times

Last updated: Nov 14 '11