{ } Raw JSON

bundles / scipy latest / scipy / interpolate / _cubic / Akima1DInterpolator

class

scipy.interpolate._cubic:Akima1DInterpolator

source: /scipy/interpolate/_cubic.py :401

Signature

class   Akima1DInterpolator ( x y axis = 0 * method : Literal['akima', 'makima'] = akima extrapolate : bool | None = None )

Members

Summary

Akima "visually pleasing" interpolator (C1 smooth).

Extended Summary

Fit piecewise cubic polynomials, given vectors x and y. The interpolation method by Akima uses a continuously differentiable sub-spline built from piecewise cubic polynomials. The resultant curve passes through the given data points and will appear smooth and natural.

Parameters

x : ndarray, shape (npoints, )

1-D array of monotonically increasing real values.

y : ndarray, shape (..., npoints, ...)

N-D array of real values. The length of y along the interpolation axis must be equal to the length of x. Use the axis parameter to select the interpolation axis.

axis : int, optional

Axis in the y array corresponding to the x-coordinate values. Defaults to axis=0.

method : {'akima', 'makima'}, optional

If "makima", use the modified Akima interpolation [2]. Defaults to "akima", use the Akima interpolation [1].

extrapolate : {bool, None}, optional

If bool, determines whether to extrapolate to out-of-bounds points based on first and last intervals, or to return NaNs. If None, extrapolate is set to False.

Methods

__call__
derivative
antiderivative
integrate
solve
roots

Notes

Use only for precise data, as the fitted curve passes through the given points exactly. This routine is useful for plotting a pleasingly smooth curve through a few given points for purposes of plotting.

Let be the slopes of the interval . Akima's derivative at is defined as:

In the Akima interpolation [1] (method="akima"), the weights are:

In the modified Akima interpolation [2] (method="makima"), to eliminate overshoot and avoid edge cases of both numerator and denominator being equal to 0, the weights are modified as follows:

Array API Standard Support

Akima1DInterpolator has experimental support for Python Array API Standard compatible backends in addition to NumPy. Please consider testing these features by setting an environment variable SCIPY_ARRAY_API=1 and providing CuPy, PyTorch, JAX, or Dask arrays as array arguments. The following combinations of backend and device (or other capability) are supported.

====================  ====================  ====================
Library               CPU                   GPU
====================  ====================  ====================
NumPy                 ✅                     n/a                 
CuPy                  n/a                   ⛔                   
PyTorch               ✅                     ⛔                   
JAX                   ⛔                     ⛔                   
Dask                  ⛔                     n/a                 
====================  ====================  ====================

See dev-arrayapi for more information.

Examples

Comparison of ``method="akima"`` and ``method="makima"``:
import numpy as np
from scipy.interpolate import Akima1DInterpolator
import matplotlib.pyplot as plt
x = np.linspace(1, 7, 7)
y = np.array([-1, -1, -1, 0, 1, 1, 1])
xs = np.linspace(min(x), max(x), num=100)
y_akima = Akima1DInterpolator(x, y, method="akima")(xs)
y_makima = Akima1DInterpolator(x, y, method="makima")(xs)
fig, ax = plt.subplots()
ax.plot(x, y, "o", label="data")
ax.plot(xs, y_akima, label="akima")
ax.plot(xs, y_makima, label="makima")
ax.legend()
fig.show()
The overshoot that occurred in ``"akima"`` has been avoided in ``"makima"``.

See also

CubicSpline

Cubic spline data interpolator.

PPoly

Piecewise polynomial in terms of coefficients and breakpoints

PchipInterpolator

PCHIP 1-D monotonic cubic interpolator.

Aliases

  • scipy.interpolate.Akima1DInterpolator

Referenced by