Ask Your Question
1

interpolated 2D plot

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

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?

Thanks.

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
4

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

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")
show(p)

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

Comments

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 +0100 )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

Stats

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

Seen: 1,121 times

Last updated: Nov 14 '11