
- SciPy - Home
- SciPy - Introduction
- SciPy - Environment Setup
- SciPy - Basic Functionality
- SciPy - Relationship with NumPy
- SciPy Clusters
- SciPy - Clusters
- SciPy - Hierarchical Clustering
- SciPy - K-means Clustering
- SciPy - Distance Metrics
- SciPy Constants
- SciPy - Constants
- SciPy - Mathematical Constants
- SciPy - Physical Constants
- SciPy - Unit Conversion
- SciPy - Astronomical Constants
- SciPy - Fourier Transforms
- SciPy - FFTpack
- SciPy - Discrete Fourier Transform (DFT)
- SciPy - Fast Fourier Transform (FFT)
- SciPy Integration Equations
- SciPy - Integrate Module
- SciPy - Single Integration
- SciPy - Double Integration
- SciPy - Triple Integration
- SciPy - Multiple Integration
- SciPy Differential Equations
- SciPy - Differential Equations
- SciPy - Integration of Stochastic Differential Equations
- SciPy - Integration of Ordinary Differential Equations
- SciPy - Discontinuous Functions
- SciPy - Oscillatory Functions
- SciPy - Partial Differential Equations
- SciPy Interpolation
- SciPy - Interpolate
- SciPy - Linear 1-D Interpolation
- SciPy - Polynomial 1-D Interpolation
- SciPy - Spline 1-D Interpolation
- SciPy - Grid Data Multi-Dimensional Interpolation
- SciPy - RBF Multi-Dimensional Interpolation
- SciPy - Polynomial & Spline Interpolation
- SciPy Curve Fitting
- SciPy - Curve Fitting
- SciPy - Linear Curve Fitting
- SciPy - Non-Linear Curve Fitting
- SciPy - Input & Output
- SciPy - Input & Output
- SciPy - Reading & Writing Files
- SciPy - Working with Different File Formats
- SciPy - Efficient Data Storage with HDF5
- SciPy - Data Serialization
- SciPy Linear Algebra
- SciPy - Linalg
- SciPy - Matrix Creation & Basic Operations
- SciPy - Matrix LU Decomposition
- SciPy - Matrix QU Decomposition
- SciPy - Singular Value Decomposition
- SciPy - Cholesky Decomposition
- SciPy - Solving Linear Systems
- SciPy - Eigenvalues & Eigenvectors
- SciPy Image Processing
- SciPy - Ndimage
- SciPy - Reading & Writing Images
- SciPy - Image Transformation
- SciPy - Filtering & Edge Detection
- SciPy - Top Hat Filters
- SciPy - Morphological Filters
- SciPy - Low Pass Filters
- SciPy - High Pass Filters
- SciPy - Bilateral Filter
- SciPy - Median Filter
- SciPy - Non - Linear Filters in Image Processing
- SciPy - High Boost Filter
- SciPy - Laplacian Filter
- SciPy - Morphological Operations
- SciPy - Image Segmentation
- SciPy - Thresholding in Image Segmentation
- SciPy - Region-Based Segmentation
- SciPy - Connected Component Labeling
- SciPy Optimize
- SciPy - Optimize
- SciPy - Special Matrices & Functions
- SciPy - Unconstrained Optimization
- SciPy - Constrained Optimization
- SciPy - Matrix Norms
- SciPy - Sparse Matrix
- SciPy - Frobenius Norm
- SciPy - Spectral Norm
- SciPy Condition Numbers
- SciPy - Condition Numbers
- SciPy - Linear Least Squares
- SciPy - Non-Linear Least Squares
- SciPy - Finding Roots of Scalar Functions
- SciPy - Finding Roots of Multivariate Functions
- SciPy - Signal Processing
- SciPy - Signal Filtering & Smoothing
- SciPy - Short-Time Fourier Transform
- SciPy - Wavelet Transform
- SciPy - Continuous Wavelet Transform
- SciPy - Discrete Wavelet Transform
- SciPy - Wavelet Packet Transform
- SciPy - Multi-Resolution Analysis
- SciPy - Stationary Wavelet Transform
- SciPy - Statistical Functions
- SciPy - Stats
- SciPy - Descriptive Statistics
- SciPy - Continuous Probability Distributions
- SciPy - Discrete Probability Distributions
- SciPy - Statistical Tests & Inference
- SciPy - Generating Random Samples
- SciPy - Kaplan-Meier Estimator Survival Analysis
- SciPy - Cox Proportional Hazards Model Survival Analysis
- SciPy Spatial Data
- SciPy - Spatial
- SciPy - Special Functions
- SciPy - Special Package
- SciPy Advanced Topics
- SciPy - CSGraph
- SciPy - ODR
- SciPy Useful Resources
- SciPy - Reference
- SciPy - Quick Guide
- SciPy - Cheatsheet
- SciPy - Useful Resources
- SciPy - Discussion
SciPy - interpolate.PchipInterpolator() Function
scipy.interpolate.PchipInterpolator() is a monotonic spline interpolation method in Python's SciPy library. It constructs a piecewise cubic Hermite interpolating polynomial (PCHIP) that preserves the shape and monotonicity of the input data by making it ideal for smoothly interpolating data without overshooting especially for non-oscillating datasets.
When compared to spline interpolation PCHIP avoids oscillations between points ensuring that intermediate values respect the trends of the original data. This function takes x and y values as input by creating an interpolator object that can evaluate new y-values at any intermediate x-points. This is especially useful in data visualization and numerical analysis.
Syntax
Following is the syntax of the function scipy.interpolate.PchipInterpolator() to perform monotonic spline interpolation −
PchipInterpolator(x, y, axis=0, extrapolate=None)
Parameters
Here are the parameters of the scipy.interpolate.PchipInterpolator() function −
- x: The 1-dimensional array of x-coordinates which must be strictly increasing.
- y: The array of y-coordinates corresponding to each x value.
- axis: This parameter specifies the axis in y to which interpolation is applied. Default value is 0.
- extrapolate: This parameter controls extrapolation behavior for values outside the x range. If None then extrapolation is allowed and if False then it raises an error for values beyond the range.
Return Value
The scipy.interpolate.PchipInterpolator() function returns an interpolator object that can be used to evaluate the interpolated values at any desired x-coordinates within the range of the input data.
Basic Interpolation
Following is the example of the scipy.interpolate.PchipInterpolator() function which is used to perform monotonic spline interpolation. Here in this example given some data points to create a PCHIP interpolator to estimate values between them smoothly −
from scipy.interpolate import PchipInterpolator import numpy as np import matplotlib.pyplot as plt # Define data points x = [0, 1, 2, 3, 4] y = [0, 1, 0, 1, 0] # Create the interpolator pchip = PchipInterpolator(x, y) # Generate points for a smooth curve x_new = np.linspace(0, 4, 100) y_new = pchip(x_new) # Plot plt.plot(x, y, 'o', label='Original points') plt.plot(x_new, y_new, '-', label='PCHIP interpolation') plt.legend() plt.show()
Here is the output of the scipy.interpolate.PchipInterpolator() function −

Monotonic Data Interpolation
When interpolating monotonic data PchipInterpolator() function is particularly effective because it ensures the interpolated values stay within the range and trend of the data without oscillations or overshooting. This makes it ideal for smooth transitions in cumulative or sequential data. Below is the example for our better understanding −
from scipy.interpolate import PchipInterpolator import numpy as np import matplotlib.pyplot as plt # Define monotonic data points (increasing trend) x = [0, 1, 2, 3, 4, 5] y = [0, 0.5, 0.75, 0.8, 0.9, 1.0] # Create the PCHIP interpolator pchip = PchipInterpolator(x, y) # Generate smooth x-points for interpolation x_new = np.linspace(0, 5, 100) y_new = pchip(x_new) # Plot the original points and interpolated curve plt.plot(x, y, 'o', label='Original points') plt.plot(x_new, y_new, '-', label='Monotonic PCHIP interpolation') plt.xlabel('X') plt.ylabel('Y') plt.legend() plt.title('Monotonic Data Interpolation using PCHIP') plt.show()
Here is the output of the scipy.interpolate.PchipInterpolator() function used on monotonic data −

Interpolating and Differentiating
Interpolating and differentiating with scipy.interpolate.PchipInterpolator() function involves creating a smooth interpolation from data points and then obtaining derivatives of this interpolated function. This is particularly useful for analyzing the rate of change in data or smoothing noisy data. Following is the example −
import numpy as np from scipy.interpolate import PchipInterpolator import matplotlib.pyplot as plt # Sample data points x = np.array([0, 1, 2, 3, 4, 5]) y = np.array([0, 0.5, 2, 1.5, 0.5, 0]) # Create the PCHIP interpolator pchip = PchipInterpolator(x, y) # Define new x values for interpolation x_new = np.linspace(0, 5, 100) y_new = pchip(x_new) # Calculate the first derivative using the derivative method y_derivative = pchip.derivative()(x_new) # Plot the original data, interpolated values, and the derivative plt.figure(figsize=(10, 6)) # Original data and interpolation plot plt.subplot(2, 1, 1) plt.plot(x, y, 'o', label='Original data') plt.plot(x_new, y_new, label='PCHIP Interpolation') plt.title('Interpolation and Derivative using PCHIP') plt.legend() # Derivative plot plt.subplot(2, 1, 2) plt.plot(x_new, y_derivative, 'r', label="PCHIP Derivative") plt.xlabel('x') plt.ylabel("y'") plt.legend() plt.tight_layout() plt.show()
Here is the output of the scipy.interpolate.PchipInterpolator() function with Interpolation and Derivatives −
