hope this fix your issue nearest "snaps" to the nearest data point. zero is a zero order spline. It's value at any point is the last raw value seen. linear performs linear interpolation and slinear uses a first order spline. They use different code and can produce similar but subtly different results. quadratic uses second order spline interpolation. cubic uses third order spline interpolation. Note that the k parameter can also accept an integer specifying the order of spline interpolation. code :
import numpy as np
import matplotlib.pyplot as plt
import scipy.interpolate as interpolate
np.random.seed(6)
kinds = ('nearest', 'zero', 'linear', 'slinear', 'quadratic', 'cubic')
N = 10
x = np.linspace(0, 1, N)
y = np.random.randint(10, size=(N,))
new_x = np.linspace(0, 1, 28)
fig, axs = plt.subplots(nrows=len(kinds)+1, sharex=True)
axs[0].plot(x, y, 'bo')
axs[0].set_title('raw')
for ax, kind in zip(axs[1:], kinds):
new_y = interpolate.interp1d(x, y, kind=kind)(new_x)
ax.plot(new_x, new_y, 'ro')
ax.set_title(kind)
plt.show()
Share :

Does scipy.interpolate.interp1d have problems with decimal values leading the x values?
By : user3641646
Date : March 29 2020, 07:55 AM
Any of those help inter1d returns a function which allows you to interpolate within the domain of the data. When you use code :
interp1d(np.array([1.1, 2.2, 3.3, 4.4, 5.5, 6.6]),
np.array([2, 4, 6, 8, 10, 12]), kind='cubic')(np.linspace(1, 6, num=40))
ValueError: A value in x_new is below the interpolation range.
np.array([1.0, 2.2, 3.3, 4.4, 5.5, 6.6])

scipy.interpolate.interp1d 'kind' not working
By : Song.Sun
Date : March 29 2020, 07:55 AM
seems to work fine You're only plotting it at the x values you're using to fit it, so you're only seeing the agreement there and lines drawn between those points. If you plot it at more points between 0 and 10 (e.g. np.linspace(0, 10, 100), you'll start to see the difference:

scipy.interpolate.interp1d with kind="previous" doesn't extrapolate as expected
By : Anders Taylor
Date : November 17 2020, 04:01 AM

python: interpolate with scipy using interp1d fails for kind=4 / fourth order
By : user3677014
Date : March 29 2020, 07:55 AM
should help you out I posted the question too quickly... it seems to be possible with splrep and splev: code :
f4 = scipy.interpolate.splrep(x, y, k=4)
yi4 = scipy.interpolate.splev(xhi, f4)

Choosing between numpy.interp vs scipy.interpolate.interp1d (with kind='linear')
By : Sakshi Sharma
Date : March 29 2020, 07:55 AM
To fix this issue Numpy.interp does not handle complexvalued data or ndim>1, while scipy.interp1d does both. OTOH, numpy's interpolator is much faster (and is likely faster still in more recent numpy version).

