Recently, I had a need for a monotonic piece-wise cubic Hermite interpolator.   Matlab provides the function "pchip" (Piecewise Cubic Hermite Interpolator), but when I Googled I didn't find any Python equivalent.   I tried "interp1d()" from scipy.interpolate but this was a standard cubic spline using all of the data - not a piece-wise cubic spline.  This type of interpolator wasn't up to my needs because it tends to ring between points where there are sharp transitions because it isn't monotonic and it uses all of the data - which makes the interpolator "miss" sharp breaks in the data.

I had access to Matlab documentation, so I spent a some time tracing through the code to figure out how I might write a Python duplicate.  This was an massive exercise in frustration and a potent reminder on why I love Python and use Matlab only under duress.  I find typical Matlab code is poorly documented (if at all) and that apparently includes the code included in their official releases.  I also find Matlab syntax “dated” and the code very difficult to “read”.

Wikipedia to the rescue:

http://en.wikipedia.org/wiki/Cubic_Hermite_spline
http://en.wikipedia.org/wiki/Monotone_cubic_interpolation

Not to be deterred, these two very well written Wikipedia entries explained in simple language how to compute the interpolant.  Hats off to whoever wrote these entries – they are excellent.  The result was a surprising small amount of code considering the Matlab code was approaching 10 pages of incomprehensible code. Again - strong evidence that things are just better in Python...

The resulting code: