Reputation: 59
I'm trying to understand how interpolation works and what results in the zig zagging when interpolating in my curve. Am I right in assuming that interpolation considers points in the order inputted or, as I think there might be, is there something more complicated going on?
My output from a scatted curve
from scipy import interpolate
yao = np.asarray(yo[0::10])
xao = np.asarray(xo[0::10])
#plt.plot(xao, yao)
print(len(xao))
okayo = np.where(np.abs(np.diff(xao)) + np.abs(np.diff(yao)) > 0)
xpo = np.r_[xao[okayo], xao[-1]]
print(len(xpo))
ypo = np.r_[yao[okayo], yao[-1]]
tcko, uo = interpolate.splprep([xpo, ypo], s=3, k=1, per=False)
xo, yo = interpolate.splev(np.linspace(0, 1, 100), tcko)
fig = plt.figure()
ax = plt.subplot(111)
ax.plot(xao, yao, '.', markersize=2)
ax.plot(xo, yo, alpha=0.5)
As opposed to when I input fewer points in a known order
I thought I was understanding interpolation but this zig zagging is confusing me a lot. Any help in understanding would be great, thank you.
Upvotes: 0
Views: 233
Reputation: 316
Your data is unavailable so it's not posible to reproduce the results, but graphs looks reasonable. Most likely the function you use consider your input as a time series data, for example on the upper graph interpolation is correct if you expect signal values to bounce from 500 to 1000, when you specify order on the bottom graph, you basically input another signal where values change smoothly and interpolated values do so.
Upvotes: 1