>
> 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 inline
import matplotlib.pyplot as plt
from IPython.display import display
import ipywidgets as widgets
from ipywidgets import interact, Button, HBox, VBox
import numpy as np

# plot func
t = 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 plot
sinePlot(f=1.0)
display(tab)

# on slider change
def on_slider_change(change):
    #print(change['new'])
    sinePlot(change['new'])
    
mySlider.observe(on_slider_change, names='value')

<https://lh3.googleusercontent.com/-kVN1vq6077E/V75YKixdLfI/AAAAAAAAFQc/wx-HL9GQhGUqudZiNTKHAe5bymsy2YbvgCLcB/s1600/Screen%2BShot%2B2016-08-24%2Bat%2B9.20.28%2BPM.png>

<https://lh3.googleusercontent.com/-3IIB_aJYQE8/V75YPaPry6I/AAAAAAAAFQg/akhhqziH0mQaJWjsrbfUlth-P2nU3P22QCLcB/s1600/Screen%2BShot%2B2016-08-24%2Bat%2B9.20.44%2BPM.png>


-- 
You received this message because you are subscribed to the Google Groups 
"Project Jupyter" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/jupyter/696b55d6-7a36-4346-b79f-191b90426521%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to