In [94]:
%matplotlib inline
import numpy as np
import seaborn.apionly as sns
from matplotlib import pyplot as plt

In [95]:
n = 100
dy = np.random.normal(size=n)
y = np.cumsum(dy)

plt.plot(y)


Out[95]:
[<matplotlib.lines.Line2D at 0x7f739494c090>]

In [96]:
x = np.arange(n)

fit = np.poly1d(np.polyfit(x,y,15))
fit

plt.plot(np.polyval(fit,x))
plt.plot(y)


Out[96]:
[<matplotlib.lines.Line2D at 0x7f7394959990>]

In [97]:
roots = np.roots(fit)
roots


Out[97]:
array([ 103.41679574 +0.j        ,   99.35271468 +4.59810406j,
         99.35271468 -4.59810406j,   83.37942881 +2.88472215j,
         83.37942881 -2.88472215j,   62.87329024+10.36442339j,
         62.87329024-10.36442339j,   50.09735177 +0.j        ,
         27.64054191+11.44912337j,   27.64054191-11.44912337j,
         31.61245838 +0.j        ,   12.15791506 +4.09096146j,
         12.15791506 -4.09096146j,    0.16447745 +1.33880033j,
          0.16447745 -1.33880033j])

In [98]:
from matplotlib.colors import ListedColormap

phase_colormap = ListedColormap(sns.husl_palette(256))

res = 500
roots_r = np.real(roots)
roots_j = np.imag(roots)
r_min, r_max = np.min(roots_r), np.max(roots_r)
j_min, j_max = np.min(roots_j), np.max(roots_j)

J, R = np.meshgrid(np.linspace(j_min,j_max,res),np.linspace(r_min,r_max,res))

z = R + J * 1j

P = np.polyval(fit,z)
plt.imshow(np.angle(P), cmap=phase_colormap)


Out[98]:
<matplotlib.image.AxesImage at 0x7f73947bb4d0>