In order to interpolate, you can use scipy.interpolate.interp1d, which supports many different methods:
‘linear’, ‘nearest’, ‘nearest-up’, ‘zero’, ‘slinear’, ‘quadratic’,
‘cubic’, ‘previous’, or ‘next’
In order to reproduce the plot you provided, here is an example of code:
import numpy as np
from scipy.interpolate import interp1d
import matplotlib.pyplot as plt
import seaborn as sns
x = [1, 2, 3, 4, 5]
y = [1, 3, 2, 3, 1]
x_interp = np.linspace(x[0], x[-1], 1000)
methods = ['linear', 'nearest', 'nearest-up', 'zero', 'slinear', 'quadratic', 'cubic', 'previous', 'next']
fig, ax = plt.subplots()
for i, method in enumerate(methods, 0):
y_values = [y_i + 5*i for y_i in y]
y_interp = interp1d(x, y_values, kind = method)(x_interp)
sns.lineplot(x_interp, y_interp, label = method, ax = ax)
sns.scatterplot(x, y_values, ax = ax)
ax.legend(frameon = False, loc = 'upper left', bbox_to_anchor = (1.05, 1))
plt.tight_layout()
plt.show()
