Skip to main content
v2026.11,858 entries · CC-BY 4.0

SciPy Interpolate: Which Function to Use

Choose the right scipy.interpolate function for 1-D, gridded or scattered data, and avoid the extrapolation and boundary-condition surprises.

Written and maintained by CASRAI Editorial Board

Last updated

SciPy interpolation lives in scipy.interpolate, and the right function depends on the shape of your data. The SciPy documentation says the choice “depends on the data: whether it is one-dimensional, is given on a structured grid, or is unstructured”, with smoothness as the second factor. This guide turns that into a decision path (1-D, gridded, scattered), shows the two settings that most often surprise people (bc_type versus extrapolate, and extrapolation differences from NumPy), and lists the failure modes you will meet when reading the output. For plain piecewise-linear lookups with NumPy alone, see Interpolation in NumPy: np.interp Step by Step.

What scipy.interpolate is used for in research

Interpolation estimates values between measured points: reading an unknown off a calibration or standard curve, resampling an instrument trace onto a common time axis, filling a coarse measurement grid before plotting, or evaluating a fitted curve’s derivative. If your goal is a model fitted through noisy data rather than a curve that passes through every point, regression is the better tool; see Linear Regression Calculator: Formulas, Worked Examples, Excel, R and Python. For a lab example of reading values from a curve, see BCA Protein Assay: Working Reagent, Standard Curve and Calculating Concentration.

Install or access (official source only)

The SciPy installation page (scipy.org/install) lists these routes:

  • python -m pip install scipy
  • conda install scipy (the page also lists mamba install scipy)

Then import what you need, for example from scipy.interpolate import CubicSpline.

Which scipy.interpolate function to use

Start from the shape of the data. Rows follow the SciPy interpolation tutorial and the class reference pages.

Your data Use What the documentation says
1-D, straight lines between points numpy.interp Piecewise linear.
1-D, smooth curve CubicSpline Continuous second derivative.
1-D, must not overshoot PchipInterpolator Monotone; attempts to preserve the local shape implied by the data. Cubic splines can overshoot.
1-D, a spline of another degree make_interp_spline Degree set by k; the default is 3.
N-D values on a regular grid RegularGridInterpolator Methods: nearest, linear, slinear, cubic, quintic, pchip. The functional form is interpn.
N-D scattered points griddata Delegates to NearestNDInterpolator (‘nearest’), LinearNDInterpolator (‘linear’) or CloughTocher2DInterpolator (‘cubic’, 2-D only). RBFInterpolator is the radial-basis-function option.

Step-by-step task

1. One-dimensional data: CubicSpline

  1. Put x in strictly increasing order. The documentation requires x to be “real, finite and in strictly increasing order”.
  2. Build the spline and evaluate it:
    from scipy.interpolate import CubicSpline
    spl = CubicSpline([1, 2, 3, 4, 5, 6], [1, 4, 8, 16, 25, 36])
    spl(2.5)        # 5.57
  3. For a derivative, pass nu: spl(xnew, nu=1) returns the first derivative.

The signature is CubicSpline(x, y, axis=0, bc_type='not-a-knot', extrapolate=None).

2. Boundary conditions versus extrapolation

These two arguments do different jobs, and mixing them up is the most common source of confusion. bc_type affects how the spline is constructed; extrapolate affects how it is evaluated outside the data range.

bc_type Meaning in the documentation
'not-a-knot' The default.
'periodic' The first and last y values must match.
'clamped' First derivative is zero at the ends.
'natural' Second derivative is zero at the ends.
2-tuple A condition specified for each end.

For extrapolate: True extends the end intervals, False returns NaN outside the range, and 'periodic' repeats. The default None becomes 'periodic' when bc_type='periodic' and True otherwise.

A three-point example shows the difference:

spl = CubicSpline([0, 1, 2], [0, 1, 0], extrapolate=False)
spl([-1, 0.5, 3])   # [nan, 0.75, nan]
# with extrapolate=True: [-3., 0.75, -3.]

3. Data that must not overshoot: PCHIP

PchipInterpolator takes no bc_type, and the documentation notes there is no way to construct a truly periodic PCHIP interpolant. It is only once continuously differentiable, so you trade smoothness for shape preservation.

4. Data on a regular grid: RegularGridInterpolator

from scipy.interpolate import RegularGridInterpolator
interp = RegularGridInterpolator(fit_points, values)
interp(test_points, method='linear')

Out-of-range behaviour is set at construction: bounds_error=False with fill_value=None extrapolates, and a number as fill_value fills out-of-bounds points with that number.

5. Scattered points: griddata

Call griddata with the method that matches the table above. When dimensions have very different units or magnitudes, the documentation advises: “Consider rescaling the data before interpolating or use the rescale=True keyword argument to griddata.”

Output and how to read it

  • NaN means no extrapolation was allowed. With extrapolate=False, points outside the x range come back as NaN, as in the example above. It is a signal, not a bug.
  • Extrapolated values can be far from the data. The same three points give -3 at x = -1 and x = 3 when extrapolation is on, where the data itself never goes below 0.
  • Cubic splines can overshoot. If the output wiggles between points that you expect to be monotone, switch to PchipInterpolator. On grids, the documentation suggests the pchip method of RegularGridInterpolator if spline methods produce ringing.
  • NumPy and SciPy do not extrapolate the same way. With x = np.linspace(0, 5, 11) and y = 2 * x, make_interp_spline with k=1 evaluated at [-1, 6] returns [-2., 12.], while np.interp([-1, 6], x, y) returns [0., 10.]. The spline continues the line; np.interp holds the end values.

Troubleshooting

x is not strictly increasing

Sort the pair of arrays together by x and remove duplicate x values before building a CubicSpline.

bc_type=’periodic’ is rejected

The first and last y values must match. If your signal is only approximately periodic, use another boundary condition.

Scattered results look distorted along one axis

Axes with very different scales dominate distance calculations. Rescale the inputs, or pass rescale=True to griddata.

The cubic method is not available for 3-D scattered data

The ‘cubic’ method of griddata maps to CloughTocher2DInterpolator, which is 2-D only. Use ‘linear’ or ‘nearest’, or RBFInterpolator.

Free alternatives and legacy replacements

Situation Option Source note
Piecewise-linear 1-D lookup with no SciPy dependency numpy.interp Holds end values outside the range (example above).
Existing code uses interp1d The replacements in the SciPy 1-D tutorial The class reference calls interp1d legacy: it “will no longer receive updates”, and there are no plans to remove it.
Existing code uses interp2d RegularGridInterpolator The interp2d transition guide names it the recommended alternative; interp2d silently switches between regular-grid and scattered interpolation based on array lengths.

For a statistics workflow around the same Python stack, see ANOVA in Python with statsmodels.

FAQ

What is the difference between scipy interpolate and scipy interpolation?

None in practice. scipy.interpolate is the module; “interpolation” is the task. The SciPy user guide covers both under “Interpolation (scipy.interpolate)”.

Is interp1d still available?

Yes, but the SciPy reference marks it legacy: it will no longer receive updates, and new code is advised to use the modern alternatives in the 1-D interpolation tutorial.

Does np.interp extrapolate?

Not beyond the end values. In a check with x = np.linspace(0, 5, 11) and y = 2 * x, np.interp([-1, 6], x, y) returned [0., 10.] where a degree-1 spline returned [-2., 12.].

Which function should I use for gridded data?

RegularGridInterpolator, with a method from nearest, linear, slinear, cubic, quintic or pchip.

Sources

Follow CASRAI

Research-administration guidance, standards updates and independent tool reviews.

Ask CASRAI · free to try

Ask about SciPy Interpolate: Which Function to Use

Ask your first 2 questions free below. Subscribers get 150 a day for $29 a month.

An AI assistant specialized in research administration. It cites the sources behind every answer, labels web answers and says when it can't answer.

Answers draw on CASRAI's guides and dictionary plus the federal and funder documents we index: Federal Register, Grants.gov, Regulations.gov and UKRI.

Works on this site and inside Claude, Cursor and the AI tools you already use.

Everything CASRAI publishes — this page, the dictionary, the guides and the news — stays free to read, with no account and no card.

Referenced across the research world

University of Cambridge logoColumbia University logoCrossref logoUniversity of Edinburgh logoHarvard University logoUniversity of Oxford logoPrinceton University logoStanford School of Medicine logoUniversity College London logoORCID logoUniversity of Cambridge logoColumbia University logoCrossref logoUniversity of Edinburgh logoHarvard University logoUniversity of Oxford logoPrinceton University logoStanford School of Medicine logoUniversity College London logoORCID logo
  • University of Cambridge logo
  • Columbia University logo
  • Crossref logo
  • University of Edinburgh logo
  • Harvard University logo
  • University of Oxford logo
  • Princeton University logo
  • Stanford School of Medicine logo
  • University College London logo
  • ORCID logo

View CASRAI adoption →

Ask CASRAI · Regulatory Radar

Research-admin question? Get an answer that links its sources.

An AI assistant specialized in research administration. Every answer links its sources to check before you act. 2 questions free, no account. $29/month after.

  • Answers draw on CASRAI's guides and dictionary plus the federal and funder documents we index: Federal Register, Grants.gov, Regulations.gov and UKRI.
  • Every answer numbers its sources and links each one, so you can check the source yourself.