I try to interpolate some data points generated by a self-defined function. All points should like very similar to a sine curve. When I run
fit_curve = spitpl.interp1d(u,v,kind="cubic")
x=gamma*np.linspace(-3,3,3000)
plt.plot(x,fitcurve(x), 'r-')
sometimes it fails (see the attached figures). I just slightly change a parameter in the function for the two cases, and the generated points just change slightly. They all look pretty well-behaved in a scatter plot, but the interpolating curve will change from a very good fit to a wildly behaving curve. Any ideas why is that? When I just slinear
then it works fine, but I want a higher accuracy from cubic spline.
when it is good:
a zoom-in figure:
when it is bad (generated points are slightly different due to a change in function parameter)
a zoom-in figure