I am generating a graph of a cubic spline through a given set of data points:
import matplotlib.pyplot as plt
import numpy as np
from scipy import interpolate
x = np.array([1, 2, 4, 5]) # sort data points by increasing x value
y = np.array([2, 1, 4, 3])
arr = np.arange(np.amin(x), np.amax(x), 0.01)
s = interpolate.CubicSpline(x, y)
plt.plot(x, y, 'bo', label='Data Point')
plt.plot(arr, s(arr), 'r-', label='Cubic Spline')
plt.legend()
plt.show()
How can I get the spline equations from CubicSpline? I need the equations in the form:
I've attempted various methods to get the coefficients, but they all use data that was obtained using different data other than just the data points.