In [46]:
from bokeh.io import vform
from bokeh.models import CustomJS, ColumnDataSource, Slider
from bokeh.plotting import Figure, output_file, show
import numpy as np
In [47]:
output_file("callback.html")
x = np.arange(0,10000,1)
y = 0.5 * x
In [48]:
source = ColumnDataSource(data=dict(x=x, y=y))
plot = Figure(plot_width=400, plot_height=400, webgl=True)
plot.circle('x', 'y', source=source, line_width=3, line_alpha=0.6)
Out[48]:
In [49]:
callback = CustomJS(args=dict(source=source), code="""
var data = source.get('data');
var f = cb_obj.get('value')
x = data['x']
y = data['y']
for (i = 0; i < x.length; i++) {
y[i] = Math.pow(x[i], f)
}
source.trigger('change');
""")
In [50]:
slider = Slider(start=0.1, end=4, value=1, step=.1, title="power", callback=callback)
layout = vform(slider, plot)
In [51]:
show(layout)
In [ ]: