scipy.interpolate.PchipInterpolator#

class PchipInterpolator(x, y, axis=0, extrapolate=None)[source]#

PCHIP 1-D monotonic cubic interpolation.

x and y are arrays of values used to approximate some function f, with y = f(x). The interpolant uses monotonic cubic splines to find the value of new points. (PCHIP stands for Piecewise Cubic Hermite Interpolating Polynomial).

Parameters#

xndarray, shape (npoints, )

A 1-D array of monotonically increasing real values. x cannot include duplicate values (otherwise f is overspecified)

yndarray, shape (…, npoints, …)

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

Deprecated since version 1.13.0: Complex data is deprecated and will raise an error in SciPy 1.15.0. If you are trying to use the real components of the passed array, use np.real on y.

axisint, optional

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

extrapolatebool, optional

Whether to extrapolate to out-of-bounds points based on first and last intervals, or to return NaNs.

Methods#

__call__ derivative antiderivative roots

See Also#

CubicHermiteSpline : Piecewise-cubic interpolator. Akima1DInterpolator : Akima 1D interpolator. CubicSpline : Cubic spline data interpolator. PPoly : Piecewise polynomial in terms of coefficients and breakpoints.

Notes#

The interpolator preserves monotonicity in the interpolation data and does not overshoot if the data is not smooth.

The first derivatives are guaranteed to be continuous, but the second derivatives may jump at \(x_k\).

Determines the derivatives at the points \(x_k\), \(f'_k\), by using PCHIP algorithm [1].

Let \(h_k = x_{k+1} - x_k\), and \(d_k = (y_{k+1} - y_k) / h_k\) are the slopes at internal points \(x_k\). If the signs of \(d_k\) and \(d_{k-1}\) are different or either of them equals zero, then \(f'_k = 0\). Otherwise, it is given by the weighted harmonic mean

\[\frac{w_1 + w_2}{f'_k} = \frac{w_1}{d_{k-1}} + \frac{w_2}{d_k}\]

where \(w_1 = 2 h_k + h_{k-1}\) and \(w_2 = h_k + 2 h_{k-1}\).

The end slopes are set using a one-sided scheme [2].

References#

__init__(x, y, axis=0, extrapolate=None)[source]#

Methods

__init__(x, y[, axis, extrapolate])

antiderivative([nu])

Construct a new piecewise polynomial representing the antiderivative.

construct_fast(c, x[, extrapolate, axis])

Construct the piecewise polynomial without making checks.

derivative([nu])

Construct a new piecewise polynomial representing the derivative.

extend(c, x)

Add additional breakpoints and coefficients to the polynomial.

from_bernstein_basis(bp[, extrapolate])

Construct a piecewise polynomial in the power basis from a polynomial in Bernstein basis.

from_spline(tck[, extrapolate])

Construct a piecewise polynomial from a spline

integrate(a, b[, extrapolate])

Compute a definite integral over a piecewise polynomial.

roots([discontinuity, extrapolate])

Find real roots of the piecewise polynomial.

solve([y, discontinuity, extrapolate])

Find real solutions of the equation pp(x) == y.

Attributes

c

x

extrapolate

axis