# interpolated 2D plot

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.

interpolated 2D plot

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.

add a comment

4

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.

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

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

Seen: **1,056 times**

Last updated: **Nov 14 '11**

Copyright Sage, 2010. Some rights reserved under creative commons license. Content on this site is licensed under a Creative Commons Attribution Share Alike 3.0 license.