return filled
x = np.random.normal(0, 1, 1000).cumsum()
x[::3] = np.nan
x[20:100], x[200:300], x[400:450] = np.nan, np.nan, np.nan
filled = interpolate_gaps(x, limit=2)
fig, axes = plt.subplots(nrows=2, sharex=True)
axes[0].plot(x, color='lightblue')
axes[1].plot(filled, color='lightblue')
axes[0].set(ylabel='Original Data')
axes[1].set(ylabel='Filled Data')
plt.show()
Working with NaN values in matplotlib