Hi all,
I am working with bokeh from a pandas dataframe (code below). I have a working example of adding a CheckBox group that controls the hiding/showing of series in my plot. THis works just fine. The only problem is with the legend. This part of the sample doesn’t work as I get the following error: AttributeError(“unexpected attribute ‘legend’ to GlyphRenderer, possible attributes are data_source, glyph, hover_glyph, level, name, nonselection_glyph, selection_glyph, tags, visible, x_range_name or y_range_name”,)
Clearly the GlyphRenderer doesn’t have the attribute “legend” anymore after instantiating it. But is there another way to remove the series from the legend when it’s visible property is set to False?
Cheers,
Dolf.
import pandas as pd
from bokeh.layouts import row
from bokeh.plotting import figure, curdoc
from bokeh.models import CheckboxGroup
input_table = pd.read_pickle(‘data.pickle’)
p = figure(title=“Event Troubleshooting”, x_axis_type=“datetime”)
labels =
active =
series =
for col in input_table.keys():
if col == ‘timestamp’ or col == ‘timestamp_string’:
continue
result = input_table[pd.notnull(input_table[col])][[‘timestamp’, col]]
labels.append(col)
if col.startswith(‘evt_’):
ser = p.diamond(result[‘timestamp’], result[col], legend=col,
visible=True)
active.append(len(labels)-1)
else:
ser = p.line(result[‘timestamp’], result[col], legend=col,
visible=False)
series.append(ser)
cb = CheckboxGroup(labels=labels, active=active)
def update(attr, old, new):
print(‘updating’)
for i, s in enumerate(series):
print((i, s))
if i in cb.active:
s.visible = True
s.legend = labels[i]
else:
s.visible = False
s.legend = False
cb.on_change(‘active’, update)
layout = row(cb, p)
curdoc().add_root(layout)
``