def show_in_notebook(self, fps=5, figsize=(8, 8), cmap="viridis"): # Prepare widgets play = widgets.Play(value=0, min=0, max=len(self.states) - 1, step=1, interval=int(1000 / fps), description="Press play", disabled=False) slider = widgets.IntSlider(min=0, value=0, max=len(self.states) - 1, step=1) widgets.jslink((play, 'value'), (slider, 'value')) # Visualize frames and widgets @interact(i=play) def show(i): plt.figure(figsize=figsize) plt.axis('off') plt.imshow(self.states[i], cmap=cmap) # Display on the notebook display(slider)
def replay(self): """Replay function using ipywidgets and interact TODO: - Add slider for finetuning """ play = widgets.Play(value=0, min=0, max=len(self.fig) - 1, step=1, description="Press play", disabled=False) @interact( i=play, ) def show(i): return self.fig[i]
def __init__(self, on_interact=None, output=None, overwrite_previous_output=True, feedback=False, run=True, action_kws={}, *args, **kwargs): super().__init__(on_interact=on_interact, output=output, overwrite_previous_output=overwrite_previous_output, feedback=feedback, action_kws=action_kws) self.widget = widgets.Play(*args, **kwargs) if run: self.run()
def replay_episode(self,fps = 5): # Prepare widgets play = widgets.Play( value=0, min=0, max=len(self.frame_cache) - 1, step=1, interval=int(1000/fps), description="Press play", disabled=False ) slider = widgets.IntSlider(min = 0,value = 0,max = len(self.frame_cache) - 1,step = 1) widgets.jslink((play, 'value'), (slider, 'value')) # Visualize frames and widgets @interact(i = play) def show(i): img = Image.fromarray(self.frame_cache[i]) return img display(slider)
def replay(self, interval=0.5): # Prepare widgets play = widgets.Play( value=0, min=0, max=len(self.board_stack) - 1, step=1, interval=interval * 1000, description="Press play", disabled=False, ) slider = widgets.IntSlider( min=0, value=0, max=len(self.board_stack) - 1, step=1 ) widgets.jslink((play, "value"), (slider, "value")) # Visualize frames and widgets @interact(i=play) def show(i): return self.board_stack[i] display(slider)
def play_publisher(publisher, step=1, speed=1.0, skip=None, timestamps=None): """ Interactive widget for playing back messages from a publisher. Parameters ---------- publisher: object Any object with a ``publish`` method that accepts an ``idx`` parameter and publishes a message corresponding to that index. step: int, default 1 Difference in indexes between consecutive messages, e.g. if ``step=2`` every second message will be published. speed: float, default 1.0 Playback speed. skip: int, optional Number of messages to skip with the forward and backward buttons. timestamps: array_like, datetime64 dtype, optional Timestamps of publisher messages that determine time difference between messages and total number of messages. The time difference is calculated as the mean difference between the timestamps, i.e. it assumes that the timestamps are more or less regular. If not provided, the publisher must have a ``timestamps`` attribute which will be used instead. """ from IPython.core.display import display from ipywidgets import widgets if timestamps is None: timestamps = np.asarray(publisher.timestamps) interval = np.mean(np.diff(timestamps.astype(float) / 1e6)) / speed # position bar s_idx = widgets.IntSlider(min=0, max=len(timestamps) - 1, value=0, description="Index") # forward button def button_plus(name): s_idx.value += skip or step if s_idx.value < s_idx.max else 0 forward = widgets.Button(description="►►", layout=widgets.Layout(width="50px")) forward.on_click(button_plus) # backward button def button_minus(name): s_idx.value -= skip or step if s_idx.value < s_idx.max else 0 backward = widgets.Button(description="◄◄", layout=widgets.Layout(width="50px")) backward.on_click(button_minus) # play button play = widgets.Play( interval=int(interval * step), value=0, min=s_idx.min, max=s_idx.max, step=step, description="Press play", disabled=False, ) widgets.jslink((play, "value"), (s_idx, "value")) # layout ui = widgets.HBox([s_idx, backward, play, forward]) out = widgets.interactive_output(publisher.publish, {"idx": s_idx}) display(ui, out)
bottom = widgets.FloatSlider(min=-10, max=10, value=-1, description='bottom') top = widgets.FloatSlider(min=-10, max=10, value=1, description='top') right = widgets.FloatSlider(min=-10, max=10, value=1, description='right') fine = widgets.IntSlider(min = 20, max = 100, value=50, description='Fine') Hticks = widgets.IntSlider(min = 2, max = 50, value=10, description='Hticks') Vticks = widgets.IntSlider(min = 2, max = 50, value=10, description='Vticks') function = widgets.Text( value = 'z**2' , description='w : ') frame = widgets.FloatSlider(min=0, max=100, value=100, step = 5, description='anim') play = widgets.Play(min= 0, max = 100, step = 5) widgets.jslink((play, 'value'), (frame, 'value')) interactive_plot = widgets.interactive(rect.updateFunc, w = function, left = left, right = right, top= top, bottom = bottom, fine = fine, Hticks = Hticks, Vticks = Vticks, frame = frame )