In [4]:
from IPython.html.widgets import interact, interactive, fixed
from IPython.html import widgets
from IPython.display import clear_output, display, HTML
import functools
import statsmodels

In [5]:
import matplotlib.pyplot as plt

In [6]:
max_x = np.pi*10
def plot(f1, a1, p1, f2):
    x = np.linspace(0, max_x, num=100)
    v1 = a1*np.sin(f1*x-p1) 
    v2 = np.sin(f2*x)
    plt.plot(x, v1, label='1', alpha=0.5)
    plt.plot(x, v2, label='2', alpha=0.5)
    plt.plot(x, v1+v2, label='1+2')
    plt.xlim(0, max_x)
    plt.ylim(-4, 4)
    plt.xticks(np.arange(0, max_x, step=np.pi), ['{:d}pi'.format(int(x)) for x in np.arange(max_x/np.pi) ])
interactive(plot,  f1=(0,2.0), a1=(1,2.0), p1=(0, np.pi*2), f2=(0,2.0))



In [125]:
def plot(a, e):
    nsample = 100
    x = np.linspace(0, 100, num=nsample)
    nodal = a*np.sin(2*np.pi*x/18.613)
    trend = x*0.1
    e = np.random.normal(size=nsample)*e
    y = nodal + trend + e
    X = np.c_[x, np.sin(2*np.pi*x/18.613)]
    model = statsmodels.regression.linear_model.OLS(y, statsmodels.tools.add_constant(X))
    result = model.fit()
    plt.plot(x, result.fittedvalues, label='fit' )
    plt.plot(x, y, label='obs')
    plt.plot(x, nodal+trend, label='true')
    plt.legend(loc='upper left')
    plt.ylim(-10,20)
interactive(plot, a=(0.1, 1.5), e=(0,2.0))



In [178]:
def plot(a1, p1, f1, a2, p2, f2):
    n = 50
    thin = 3
    plt.figure(figsize=(15, 8))
    x, y = map(np.squeeze, np.ogrid[0:(np.pi*2):(n*1j), 0:(np.pi*2):(n*1j)])
    Y, X = np.meshgrid(y, x)
    U = a1*np.sin(f1*X-p1)
    V = a2*np.sin(f2*Y-p2)
    norm = np.sqrt(U**2 + V**2)
    plt.pcolormesh(X, Y, norm , cmap='Blues')
    plt.quiver(X[::thin,::thin], Y[::thin,::thin], U[::thin,::thin], V[::thin,::thin])
    plt.streamplot(x, y , U, V, linewidth=norm*5, color=norm)
interactive(plot, a1=(0.0, 1.0), p1=(0,np.pi*2), f1=(0,2.0), a2=(0.0,1.0), p2=(0,np.pi*2), f2=(0,2.0))



In [ ]: