Every example I've seen of using widgets for interactive matplotlib plots in the notebook do something like this (adapted from here):
%matplotlib inline
import numpy as np
import matplotlib.pyplot as plt
from IPython.html.widgets import interact
from IPython.display import display
def sigmoid_demo(a=5,b=1):
x = np.linspace(0,10,256)
s = 1/(1+np.exp(-(x-a)/(b+0.1))) # +0.1 to avoid dividing by 0
sn = 100.0*(s-min(s))/(max(s)-min(s)) # normalize sigmoid to 0-100
# Does this have to be in this function?
fig, ax = plt.subplots(figsize=(24,6))
ax.set_xticks([])
ax.set_yticks([])
plt.plot(x,sn,lw=2,color='black')
plt.xlim(x.min(), x.max())
w=interact(sigmoid_demo,a=5,b=1)
I suspect that the responsiveness of the plot could be sped up hugely if you didn't have to create a brand new figure with plt.subplots()
or plt.figure()
each time a widget was adjusted.
I've tried a few things to move figure creation outside of the function being called by interact()
but nothing has worked.