Heads up! To view this whole video, sign in with your Courses account or enroll in your free 7-day trial. Sign In Enroll
Start a free Courses trial
to watch this video
Jupyter Notebooks have an awesome feature where they can render charts and graphs from packages like Bokeh and Matplotlib.
Update
If you experience an AttributeError
stating unexpected attribute 'plot_height' to figure
when running the code below, you may have to change plot_height
on line 11 to height
and change plot_width
to width
.
Code Snippet
Here's the code snippet from the video:
from ipywidgets import interact
import numpy as np
from bokeh.io import push_notebook, show, output_notebook
from bokeh.plotting import figure
output_notebook()
x = np.linspace(0, 2*np.pi, 2000)
y = np.sin(x)
p = figure(title='simple line example', plot_height=300, plot_width=600, y_range=(-5,5))
r = p.line(x, y, color='#2222aa', line_width=3)
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()
show(p, notebook_handle=True)
interact(update, f=["sin", "cos", "tan"], w=(0,100), A=(1,5), phi=(0, 20, 0.1))
You'll also need to run jupyter nbextension enable --py --sys-prefix widgetsnbextension
in your terminal.
Sharing your notebooks
Related Discussions
Have questions about this video? Start a discussion with the community and Treehouse staff.
Sign upRelated Discussions
Have questions about this video? Start a discussion with the community and Treehouse staff.
Sign up
You need to sign up for Treehouse in order to download course files.
Sign upYou need to sign up for Treehouse in order to set up Workspace
Sign up