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
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.
fig = go.FigureWidget()
scatt = fig.add_scatter()
fig
FigureWidget({ 'data': [{'type': 'scatter', 'uid': '0e6538cc-a0d7-11e8-bd43-645aede86e5b'}], 'layout': {} …
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.
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
interactive(children=(FloatSlider(value=3.6, description='a', max=4.0, min=1.0, step=0.01), FloatSlider(value=…