scipy.interpolate.PchipInterpolator¶
- class scipy.interpolate.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: x : ndarray
A 1-D array of monotonically increasing real values. x cannot include duplicate values (otherwise f is overspecified)
y : ndarray
A 1-D array of real values. y‘s length along the interpolation axis must be equal to the length of x. If N-D array, use axis parameter to select correct axis.
axis : int, optional
Axis in the y array corresponding to the x-coordinate values.
extrapolate : bool, optional
Whether to extrapolate to ouf-of-bounds points based on first and last intervals, or to return NaNs.
See also
Notes
The first derivatives are guaranteed to be continuous, but the second derivatives may jump at x_k.
Preserves monotonicity in the interpolation data and does not overshoot if the data is not smooth.
Determines the derivatives at the points x_k, d_k, by using PCHIP algorithm:
Let m_k be the slope of the kth segment (between k and k+1) If m_k=0 or m_{k-1}=0 or sgn(m_k) != sgn(m_{k-1}) then d_k == 0 else use weighted harmonic mean:
w_1 = 2h_k + h_{k-1}, w_2 = h_k + 2h_{k-1} 1/d_k = 1/(w_1 + w_2)*(w_1 / m_k + w_2 / m_{k-1})where h_k is the spacing between x_k and x_{k+1}.
Methods
__call__(x[, der, extrapolate]) Evaluate the PCHIP interpolant or its derivative. derivative([der]) Construct a piecewise polynomial representing the derivative.