Interpolate Curve Between Three Values
I have the following script that plots a graph: x = np.array([0,1,2]) y = np.array([5, 4.31, 4.01]) plt.plot(x, y) plt.show() The problem is, that the line goes straight from poin
Solution 1:
If you use more points than 3 you will get the same result as in the linked question. There are many ways a spline of order 3 can go through 3 points.
But you may of course reduce the order to 2.
import numpy as np
import matplotlib.pyplot as plt
from scipy.interpolate import spline
x = np.array([0,1,2])
y = np.array([5, 4.31, 4.01])
plt.plot(x, y)
xnew = np.linspace(x.min(), x.max(), 300)
smooth = spline(x, y, xnew, order=2)
plt.plot(xnew, smooth)
plt.show()
Post a Comment for "Interpolate Curve Between Three Values"