I'm trying to emulate Excel's
Insert>Scatter>Scatter with smooth lines and markers
command in Matplotlib
The scipy function interpolate creates a similar effect, with some nice examples of how to simply implement this here: How to draw cubic spline in matplotlib
However Excel's spline algorithm is also able to generate a smooth curve through just three points (e.g. x = [0,1,2] y = [4,2,1]); and it isn't possible to do this with cubic splines.
I have seen discussions that suggest that the Excel algorithm uses Catmull-Rom splines; but don't really understand these, or how they could be adapted to Matplotlib: http://answers.microsoft.com/en-us/office/forum/office_2007-excel/how-does-excel-plot-smooth-curves/c751e8ff-9f99-4ac7-a74a-fba41ac80300
Is there a simple way of modifying the above examples to achieve smooth curves through three or more points using the interpolate library?
Many thanks
By now you may have found the Wikipedia page for the Centripetal Catmull-Rom spline, but in case you haven't, it includes this sample code:
which nicely computes the interpolation for
n >= 4points like so:resulting in this
matplotlibimage:Update:
Alternatively, there is a
scipy.interpolatefunction forBarycentricInterpolatorthat appears to do what you're looking for. It is rather straightforward to use and works for cases in which you have only 3 data points.Update 2
Another option within
scipyis akima interpolation viaAkima1DInterpolator. It is as easy to implement as Barycentric, but has the advantage that it avoids large oscillations at the edge of a data set. Here's a few test cases that exhibit all the criteria you've asked for so far.