smoothinterp(newx=None, origx=None, origy=None, smoothness=None, growth=None, ensurefinite=True, keepends=True, method='linear')[source]#

Smoothly interpolate over values

Unlike np.interp(), this function does exactly pass through each data point:

  • newx (arr) – the points at which to interpolate

  • origx (arr) – the original x coordinates

  • origy (arr) – the original y coordinates

  • smoothness (float) – how much to smooth

  • growth (float) – the growth rate to apply past the ends of the data

  • ensurefinite (bool) – ensure all values are finite (including skipping NaNs)

  • method (str) – the type of interpolation to use (options are ‘linear’ or ‘nearest’)


the new y coordinates

Return type:

newy (arr)


import sciris as sc
import numpy as np
from scipy import interpolate

origy = np.array([0,0.2,0.1,0.9,0.7,0.8,0.95,1])
origx = np.linspace(0,1,len(origy))
newx = np.linspace(0,1,5*len(origy))
sc_y = sc.smoothinterp(newx, origx, origy, smoothness=5)
np_y = np.interp(newx, origx, origy)
si_y = interpolate.interp1d(origx, origy, 'cubic')(newx)
kw = dict(lw=3, alpha=0.7)
pl.plot(newx, np_y, '--', label='NumPy', **kw)
pl.plot(newx, si_y, ':',  label='SciPy', **kw)
pl.plot(newx, sc_y, '-',  label='Sciris', **kw)
pl.scatter(origx, origy, s=50, c='k', label='Data')
New in verison 3.0.0: “ensurefinite” now defaults to True; removed “skipnans” argument