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]:
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]:
In [97]:
roots = np.roots(fit)
roots
Out[97]:
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]: