This notebook shows a few examples of what's possible with the static widgets
from ipywidgets import StaticInteract, RangeWidget, RadioWidget
def multiply(a, b):
return "{0} * {1} = {2}".format(a, b, a * b)
StaticInteract(multiply,
a=RangeWidget(0, 10),
b=RangeWidget(0, 10),)
0 * 0 = 0
from ipywidgets import StaticInteract, RangeWidget, RadioWidget, DropDownWidget
def operation(a, b, op, fruit):
if op == "multiply":
return "{0} * {1} = {2} {3}".format(a, b, a * b, fruit)
elif op == "add":
return "{0} + {1} = {2} {3}".format(a, b, a + b, fruit)
else:
raise ValueError
StaticInteract(operation,
a=RangeWidget(0, 10),
b=RangeWidget(0, 10),
op=RadioWidget(["multiply", "add"]),
fruit=DropDownWidget(['apples','bananas','pears','kiwis'])
)
0 * 0 = 0 apples
from sympy import init_printing
init_printing()
from sympy import Symbol, Eq, factor
x = Symbol('x')
def factorit(n):
return Eq(x ** n - 1, factor(x ** n - 1))
factorit(4)
from ipywidgets import StaticInteract, RangeWidget
StaticInteract(factorit,
n=RangeWidget(2, 10))
%matplotlib inline
import numpy as np
import matplotlib.pyplot as plt
from ipywidgets import StaticInteract, RangeWidget, RadioWidget
def plot(amplitude, color):
fig, ax = plt.subplots(figsize=(4, 3),
subplot_kw={'axisbg':'#EEEEEE',
'axisbelow':True})
ax.grid(color='w', linewidth=2, linestyle='solid')
x = np.linspace(0, 10, 1000)
ax.plot(x, amplitude * np.sin(x), color=color,
lw=5, alpha=0.4)
ax.set_xlim(0, 10)
ax.set_ylim(-1.1, 1.1)
return fig
StaticInteract(plot,
amplitude=RangeWidget(0.1, 1.0, 0.1),
color=RadioWidget(['blue', 'green', 'red']))