#!/usr/bin/env python # coding: utf-8 # ## Interact # Here is a simple example of using the `interact` decorator from ipywidgets to create a simple set of widgets to control the parameters of a plot # In[1]: import plotly.graph_objs as go import numpy as np from ipywidgets import interact # First we'll create an empty figure, and add an empty scatter trace to it. # In[2]: fig = go.FigureWidget() scatt = fig.add_scatter() fig # Then, write an update function that inputs the frequency factor (`a`) and phase factor (`b`) and sets the `x` and `y` properties of the scatter trace. This function is decorated with the `interact` decorator from the `ipywidgets` package. The decorator parameters are used to specify the ranges of parameters that we want to sweep over. See http://ipywidgets.readthedocs.io/en/latest/examples/Using%20Interact.html for more details. # In[3]: xs=np.linspace(0, 6, 100) @interact(a=(1.0, 4.0, 0.01), b=(0, 10.0, 0.01), color=['red', 'green', 'blue']) def update(a=3.6, b=4.3, color='blue'): with fig.batch_update(): scatt.x=xs scatt.y=np.sin(a*xs-b) scatt.line.color=color # In[ ]: