IPython widgets allow you to quickly and easily create interactive APIs with Python.
To run this notebook, you'll first have to install ipywidgets
using, e.g.
$ conda install ipywidgets
You can find a full set of documentation notebooks here.
If the widgets below do not show up in the notebook, try closing the notebook and running the following command in your shell:
$ jupyter nbextension enable --py widgetsnbextension
Then open the notebook again. This enables the widgets notebook extension in the case that it's disabled.
In [ ]:
from ipywidgets import interact
In [ ]:
def times_ten(x):
return 10 * x
In [ ]:
interact(times_ten, x=10);
In [ ]:
interact(times_ten, x='(^_^)')
In [ ]:
interact(times_ten, x=True)
In [ ]:
interact(times_ten, x=(100, 200))
In [ ]:
%matplotlib inline
import numpy as np
import matplotlib.pyplot as plt
x = np.linspace(0, 10, 1000)
def plot_sine(amplitude, frequency, phase):
y = amplitude * np.sin(frequency * x - phase)
plt.plot(x, y)
plt.ylim(-6, 6)
interact(plot_sine,
amplitude=(0.0, 5.0),
frequency=(0.1, 10),
phase=(-5.0, 5.0));
Let's walk through an example from the IPython widgets documentation: the Lorenz System