This example is a demo of what you can do with a different plotting package, Bokeh. Bokeh works very nicely in a Jupyter Notebook, since it outputs a bit of HTML and Javascript. The result is a plot that can be setup to be more interactive than Matplotlib, but some of the features are different.
In [1]:
import bokeh as b
In [2]:
b.__version__
Out[2]:
In [3]:
from bokeh.plotting import figure, output_file, show
# output to static HTML file
# output_file("line.html")
b.io.output_notebook()
p = figure(plot_width=400, plot_height=400)
# add a circle renderer with a size, color, and alpha
p.circle([1, 2, 3, 4, 5], [6, 7, 2, 4, 5], size=20, color="navy", alpha=0.5)
# show the results
show(p)
In [4]:
from ipywidgets import interact
import numpy as np
from bokeh.io import push_notebook, show, output_notebook
from bokeh.plotting import figure
output_notebook()
In [5]:
x = np.linspace(0, 2*np.pi, 2000)
y = np.sin(x)
p = figure(title="simple line example", plot_height=300, plot_width=900)
r = p.line(x, y, color="#2222aa", line_width=3)
In [6]:
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
r.data_source.data['y'] = A * func(w * x + phi)
push_notebook()
In [7]:
show(p, notebook_handle=True)
Out[7]:
In [8]:
interact(update, f=["sin", "cos", "tan"], w=(0,100), A=(1,5), phi=(0, 20, 0.1))
Out[8]: