Hi, I’m a novice to Bokeh and have been trying to get a whisker plot that can change values on different toggles. While other glyphs (like circles) seem to work just fine, when I try to update glyphs upon changes in my switch object the update doesn’t occur. However, I can set the object’s visibility to false and that will work. Am I misunderstanding something about how Bokeh works?
Thanks
import numpy as np
import bokeh.io as bio
import bokeh.plotting as bp
import bokeh.models as bm
import bokeh.layouts as bl
bio.output_file('test_bokeh_whisker.html')
time_val=np.linspace(0,10,11)
(v1_val,v1_pred)=(np.zeros(11), np.random.randn(11))
(v2_val,v2_pred)=(time_val, time_val+np.random.randn(11))
data_src = bm.ColumnDataSource({
'rec_t': time_val,
'v1_val': v1_val,
'v1_pred': v1_pred,
'v2_val': v2_val,
'v2_pred': v2_pred,
})
def ver_switch(attrname, old, new):
if new=='version 1':
scatter_whiskers.update(upper='v1_pred', lower='v1_val')
elif new=='version 2':
scatter_whiskers.update(upper='v2_pred', lower='v2_val')
# scatter_whiskers.visible=False
plot = bp.figure(title='Switch Test')
scatter_whiskers = bm.Whisker(source=data_src, base='rec_t', upper='v1_val', lower='v1_pred')
plot.add_layout(scatter_whiskers)
plot.x_range=bm.Range1d(0,max(time_val)*1.02)
plot.y_range=bm.Range1d(-1,11)
ver_select = bm.Select(value='version 1', title='Mode', options=['version 1', 'version 2'])
ver_select.on_change('value', ver_switch)
res = (bl.column(ver_select,plot))
bio.show(res)