In [1]:
import plotly as py
import plotly.graph_objs as go
import ipywidgets as widgets
import numpy as np
from scipy import special
py.offline.init_notebook_mode(connected=True) # setup plotly in offline mode
In [6]:
# simple example
x = np.linspace(0, np.pi*4, 1000)
layout = go.Layout(
title = 'SIMPLE EXAMPLE',
yaxis = dict(
title = 'volts'
),
xaxis = dict(
title='nanoseconds'
)
)
trace1 = go.Scatter(
x = x,
y = np.sin(x),
mode = 'lines',
name = 'sin(x)',
line = dict(
shape = 'spline'
)
)
fig = go.Figure(data=[trace1], layout = layout)
py.offline.iplot(fig)
In [11]:
# dashboard
layout = go.Layout(
title = 'Bessel Function',
yaxis = dict(
title = 'volts'
),
xaxis = dict(
title='nanoseconds'
)
)
# to update the plot given the widgets' input
def update_plot(signals, freq):
data = []
for s in signals:
trace1 = go.Scatter(
x = x,
y = special.jv(s, freq * x),
mode = 'lines',
name = 'Bessel {}'.format(s),
line = dict(
shape = 'spline'
)
)
data.append(trace1)
fig = go.Figure(data=data, layout = layout)
py.offline.iplot(fig)
signals = widgets.SelectMultiple(options=list(range(6)),
value=(0, ),
description = "Bessel Order")
freq = widgets.FloatSlider(min=1, max=20, value=1, description="Frequency")
widgets.interactive(update_plot, signals=signals, freq=freq)
In [ ]: