
- 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.CloughTocher2DInterpolator() Function
scipy.interpolate.CloughTocher2DInterpolator() is a function in SciPy used for smooth interpolation on scattered 2D data. Based on the Clough-Tocher scheme it creates a continuously differentiable surface over triangular tessellations of the input points. This function is particularly useful for complex surfaces where standard grid-based interpolation is insufficient.
This function employs piecewise cubic polynomials over Delaunay triangulation by allowing for an accurate fit even on irregularly spaced data. Users can specify options like interpolation tolerance for more control. Its ideal for applications in computational geometry, computer graphics and surface modeling where smooth interpolation is essential.
Syntax
Following is the syntax of the function scipy.interpolate.CloughTocher2DInterpolator() used for smooth interpolation on scattered 2D data −
CloughTocher2DInterpolator(points, values, fill_value=np.nan, tol=1e-06, maxiter=400, rescale=False)
Parameters
Below are the parameters of the scipy.interpolate.CloughTocher2DInterpolator() function −
- points(array-like, shape (n, D)): 2-D array of data point coordinates or a precomputed Delaunay triangulation.
- values(float or complex, shape (npoints, )): An array of shape (n,) containing the values at the corresponding points. Each value corresponds to a point defined in points.
- fill_value(float, optional): This is the value used to fill in the interpolated values for points outside the convex hull of the input points. If the interpolation is requested at a point outside the domain this value will be returned.
- tol(float, optional): Tolerance for determining if a point is close enough to an input point. Smaller values can lead to more accurate results but may increase computational time.
- maxiter(int, optional): Maximum number of iterations allowed for the optimization algorithm used in the interpolation.
- rescale(bool, optional): If True then the input data will be rescaled to improve the conditioning of the interpolation. This can be helpful if the input data spans several orders of magnitude.
Return Value
The scipy.interpolate.CloughTocher2DInterpolator() function returns an interpolation object which allows us to interpolate values at new 2D points based on the input data.
Basic Interpolation on a Grid
Following is the example of scipy.interpolate.CloughTocher2DInterpolator() function. This example shows how to interpolate values within a 2D grid using known points −
from scipy.interpolate import CloughTocher2DInterpolator import numpy as np # Define known points (x, y) and their values points = np.array([[0, 0], [1, 0], [0, 1], [1, 1], [0.5, 0.5]]) values = np.array([0, 1, 1, 0, 0.5]) # Create the interpolator interpolator = CloughTocher2DInterpolator(points, values) # Interpolate at a new point within the convex hull print("Interpolated value at (0.75, 0.25):", interpolator(0.75, 0.25)) # Interpolate at a point outside the convex hull print("Interpolated value at (1.5, 1.5):", interpolator(1.5, 1.5)) # Returns NaN or fill_value
Here is the output of the scipy.interpolate.CloughTocher2DInterpolator() function basic example −
Interpolated value at (0.75, 0.25): 0.6401650365046423 Interpolated value at (1.5, 1.5): nan
Interpolation with Custom fill_value
When we need to distinguish points that are interpolated from those that are extrapolated by assigning a clear out-of-bounds value. Below is the example which uses the custom fill_value −
from scipy.interpolate import CloughTocher2DInterpolator import numpy as np # Define known points and their corresponding values points = np.array([[0, 0], [1, 0], [0, 1], [1, 1], [0.5, 0.5]]) values = np.array([0, 1, 1, 0, 0.5]) # Create the CloughTocher2DInterpolator with a custom fill_value interpolator = CloughTocher2DInterpolator(points, values, fill_value=-1) # Interpolate at points within the convex hull print("Interpolated value at (0.25, 0.25):", interpolator(0.25, 0.25)) # Inside the convex hull print("Interpolated value at (0.75, 0.75):", interpolator(0.75, 0.75)) # Inside the convex hull # Interpolate at a point outside the convex hull print("Interpolated value at (1.5, 1.5):", interpolator(1.5, 1.5)) # Outside the convex hull, returns -1
Here is the output of the scipy.interpolate.CloughTocher2DInterpolator() function which is used with fill_value −
Interpolated value at (0.25, 0.25): 0.3598350174937729 Interpolated value at (0.75, 0.75): 0.3598349110543353 Interpolated value at (1.5, 1.5): -1.0
Plotting Interpolated Surface
This example shows how to use CloughTocher2DInterpolator() function to generate an interpolated surface and visualize it −
import numpy as np import matplotlib.pyplot as plt from scipy.interpolate import CloughTocher2DInterpolator # Define irregularly spaced data points x = np.random.rand(10) * 10 y = np.random.rand(10) * 10 z = np.sin(x) * np.cos(y) points = np.column_stack((x, y)) # Create the interpolator interpolator = CloughTocher2DInterpolator(points, z) # Create a meshgrid for plotting grid_x, grid_y = np.mgrid[0:10:100j, 0:10:100j] grid_z = interpolator(grid_x, grid_y) # Plot the result plt.figure(figsize=(8, 6)) plt.imshow(grid_z.T, extent=(0, 10, 0, 10), origin='lower', cmap='viridis') plt.colorbar(label='Interpolated Values') plt.scatter(x, y, c=z, edgecolor='k', label='Data Points') plt.legend() plt.title("CloughTocher2DInterpolator Surface") plt.xlabel("X") plt.ylabel("Y") plt.show()
Here is the output of the scipy.interpolate.CloughTocher2DInterpolator() function which is used with fill_value −
