Graphs and Charts4:32 with Kenneth Love
Jupyter Notebooks have an awesome feature where they can render charts and graphs from packages like Bokeh and Matplotlib.
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
You need to sign up for Treehouse in order to download course files.Sign up