This example illustrates an Output
ipywidget that contains a Matplotlib plot that is controlled by a slider.
With illusionist
we make this static so it runs without a kernel.
import ipywidgets
import numpy as np
from IPython.display import display, clear_output
import matplotlib as mpl
import matplotlib.pyplot as plt
%matplotlib inline
backend_ = mpl.get_backend()
mpl.use("Agg")
ax = plt.axes()
mpl.use(backend_)
A = 5
f = ipywidgets.IntSlider(min=1, max=10, value=5)
f
out = ipywidgets.Output()
out
def update(value):
ax.clear()
out.clear_output(wait=True)
t = np.arange(0.0, f.value, 0.01)
s = A + np.sin(np.pi * t)
ax.plot(t, s)
ax.set(xlabel="time (s)", ylabel="voltage (mV)", title="About as simple as it gets, folks")
ax.grid()
with out:
display(ax.figure)
#import time
#time.sleep(5)
f.observe(update, "value")
update(None)