This demo shows off an interactive visualization using Bokeh for plotting, and Ipython interactors for widgets. The demo runs entirely inside the Ipython notebook, with no Bokeh server required.
The dropdown offers a choice of trig functions to plot, and the sliders control the frequency, amplitude, and phase.
To run, click on, Cell->Run All in the top menu, then scroll to the bottom and move the sliders.
In [1]:
from bokeh.models import ColumnDataSource
from bokeh.plotting import figure, show, output_notebook
import numpy as np
In [2]:
x = np.linspace(0, 2*np.pi, 2000)
y = np.sin(x)
In [3]:
output_notebook()
In [4]:
source = ColumnDataSource(data=dict(x=x, y=y))
p = figure(title="simple line example", plot_height=300, plot_width=600)
p.line(x, y, color="#2222aa", line_width=3, source=source, name="foo")
Out[4]:
In [5]:
def update(f, w=1, A=1, phi=0):
if f == "sin": func = np.sin
elif f == "cos": func = np.cos
elif f == "tan": func = np.tan
source.data['y'] = A * func(w * x + phi)
source.push_notebook()
In [6]:
show(p)
In [7]:
from IPython.html.widgets import interact
interact(update, f=["sin", "cos", "tan"], w=(0,100), A=(1,10), phi=(0, 10, 0.1))
Out[7]:
In [ ]: