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.
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