Spline interpolation is a method that uses piecewise-defined functions (usually polynomials) to approximate the data. In SciPy, you can use the CubicSpline function for cubic spline interpolation.
Here's an example:
import numpy as np
from scipy.interpolate import CubicSpline
import matplotlib.pyplot as plt
# Sample data points
x = np.array([0, 1, 2, 3, 4])
y = np.array([0, 2, 1, 3, 5])
# Create a cubic spline interpolation
cs = CubicSpline(x, y)
# Generate points for the interpolated curve
x_interp = np.linspace(0, 4, 100)
y_interp = cs(x_interp)
# Plot the original data and the interpolated curve
plt.plot(x, y, 'o', label='Data points')
plt.plot(x_interp, y_interp, label='Cubic Spline Interpolation')
plt.legend()
plt.show()