Examples

Animated comparisons of pyakima against SciPy’s cubic splines. The images follow the light/dark toggle in the sidebar.

Corner models

Two-panel animation. Top: as one control point slides up and down, the pyakima makima curve hugs the data while a natural cubic spline rings above and below the spike. Bottom: a zoom on a sharp kink where the non-rounded, akima, and makima corner models round the corner by differing amounts. Two-panel animation. Top: as one control point slides up and down, the pyakima makima curve hugs the data while a natural cubic spline rings above and below the spike. Bottom: a zoom on a sharp kink where the non-rounded, akima, and makima corner models round the corner by differing amounts.

The top panel slides one control point up and down: the pyakima makima fit stays local and flat on either side of the spike, while a natural cubic spline rings above and below it. The bottom panel zooms into a sharp kink to show the three corner models pyakima exports:

  1. non-rounded: Algorithm based on [1], comparable numerical behavior to GSL; note the unstable behavior is because the algorithm is non-differentiable at corners, not a peculiar limitation of this implementation [2].

  2. akima (SciPy parity) [3]. Discontinuous behavior is less severe than non-rounded; slightly more prone to overshoot, and still has special edge-case handling.

  3. makima Modified Akima Algorithm [4]; recommended default Less overshoot than akima, while mathematically guaranteed to preserve differentiability/continuous behavior at corners without special edge-case handling. Similar performance to akima in most cases.

Irregular grids

Single panel animation. As the control points slide between a regular and irregular grid, the pyakima makima curve smoothly hugs the data, while the scipy default cubic spline oscillates so strongly it extends off the plotted y axis. Single panel animation. As the control points slide between a regular and irregular grid, the pyakima makima curve smoothly hugs the data, while the scipy default cubic spline oscillates so strongly it extends off the plotted y axis.

The control points oscillate smoothly between regular uniform-grid spacing and an inverse-CDF-based spacing. Such a spacing is similar to what might be used when using Akima splines for a PSD estimation task, or in approximating a function with sharp features with as few control points as possible. Such uses with irregular grids are a key modern application of Akima splines, and are of central importance to their utility in gravitational-wave detection applications, such as using trans-dimensional MCMC to adaptively fit Akima splines to un-modeled gravitational-wave sources [5], [6], [7]. Cubic splines, such as scipy’s default CubicSpline plotted above, oscillate wildly on the same irregularly-spaced grid, which typically makes them unsuitable for such analysis tasks.

Regenerating the Demo

pyakima.demos ships as an example subpackage; run it from a source checkout so it can write the README assets:

pip install -e '.[demos]'                  # scipy, matplotlib, pygsl_lite
python -m pyakima.demos.animate_demo       # writes assets/akima_demo_{light,dark}.gif
python -m pyakima.demos.animate_grid_demo  # writes assets/akima_grid_{light,dark}.gif
python -m pyakima.demos.step_demo          # writes assets/akima_step_{light,dark}.png

References

  1. G. Engeln-Müllges & F. Uhlig, Numerical Algorithms with C, Springer, 1996, ch. 13 “Akima and Renner Subsplines,” Algorithm 13.1. ISBN 978-3-642-64682-9.

  2. Note: the internals of the GSL implementation have never been viewed by the repository author. However, calls to GSL exhibit near-identical behavior, supporting that the issue is algorithmic rather than due to implementation error.

  3. Akima, Hiroshi. “A new method of interpolation and smooth curve fitting based on local procedures.” Journal of the ACM (JACM) , 17.4, 1970, pp. 589–602.

  4. C. Moler, Makima Piecewise Cubic Interpolation, Cleve’s Corner (MathWorks blog), 2019.

  5. Detecting gravitational wave signals using a flexible model for the amplitude and frequency evolution. T Gupta, NJ Cornish. Physical Review D, 2024•APS arXiv:2404.11719.

  6. Model-agnostic gravitational-wave background characterization algorithm. T Knapp, PM Meyers, AI Renzini.Physical Review D, 2025•APS. arXiv:2507.08095

  7. “Precise analysis of gravitational waves from binary neutron star coalescence using Hilbert–Huang transform based on Akima spline interpolation.” Yoda, Itsuki et al. Progress of Theoretical and Experimental Physics (2023). DOI:10.1093/ptep/ptad101