I'm looking to update matplotlib inline plots interactively that are changed inside of tab widget without generating a series of figures one below the other (see images below -- a second,third... figure is generated every time slider changes). Obviously this can be done without the tab environment via `interact`, but I can't seem to figure out how in this short example here can I change the plot in-place (on same figure) with the Slider widget. Thanks in advance for any advice.
%matplotlib inlineimport matplotlib.pyplot as pltfrom IPython.display import displayimport ipywidgets as widgetsfrom ipywidgets import interact, Button, HBox, VBoximport numpy as np
# plot funct = np.arange(0.0, 1.0, 0.001)def sinePlot(f): x = np.linspace(0.0, 2.0, 1000) plt.plot(x,np.sin(x*np.pi*t*f))
words = "one two three four".split(' ')items = [Button(description=w) for w in words]myBox = HBox([VBox([items[0], items[1]]), VBox([items[2], items[3]])])
lst = ['P0', 'P1', 'P2']mySlider = widgets.FloatSlider(value=0.5, min=0.1, max=1, step=0.1, description=('Slider'))children = [widgets.Text(description=lst[0], width='250px'), myBox, mySlider]
tab = widgets.Tab(children=children)[tab.set_title(num, name) for num, name in enumerate(lst)]
# initial plotsinePlot(f=1.0)display(tab)
# on slider changedef on_slider_change(change): #print(change['new']) sinePlot(change['new']) mySlider.observe(on_slider_change, names='value')
I'm looking to update matplotlib inline plots interactively that are changed inside of tab widget without generating a series of figures one below the other (see images below -- a second,third... figure is generated every time slider changes). Obviously this can be done without the tab environment via `interact`, but I can't seem to figure out how in this short example here can I change the plot in-place (on same figure) with the Slider widget. Thanks in advance for any advice.