def add_lowess(ax, lines_idx=0, frac=0.2, **lowess_kwargs):
 y0 = ax.get_lines()[lines_idx]._y
 x0 = ax.get_lines()[lines_idx]._x
 lres = lowess(y0, x0, frac=frac, **lowess_kwargs)
 ax.plot(lres[:, 0], lres[:, 1], 'r', lw=1.5)
 return ax.figure

def add_lowess ( ax , lines_idx = 0 , frac = 0.2 , ** lowess_kwargs ) : y0 = ax . get_lines ( ) [ lines_idx ] . _y x0 = ax . get_lines ( ) [ lines_idx ] . _x lres = lowess ( y0 , x0 , frac = frac , ** lowess_kwargs ) ax . plot ( lres [ : , 0 ] , lres [ : , 1 ] , 'r' , lw = 1.5 ) return ax . figure
add lowess line to a plot .