I would like only visible glyphs to appear in my hover tool, however all plotted glyphs are shown.
I see this was addressed with #6120, however it does not seem to be working with my current code.
Is there something I can easily change? Not seeing anything obvious in the docs that I am missing.
After creating my figure and adding all glyphs to the hover tool, I then toggle visibility for certain glyphs with:
p.select_one({'name':'%s' % x}).visible = False
But this does not seem to remove them from the hover tool…
Relevant code:
def make_airtemp_fig(station_list, label_list, hide_list, legend_out, start, end):
'''
Create the air temp panel and plot data
Parameters
----------
station_list: list of dataframes, in legend display order
label_list: list of label strings, in legend display order
hide_list: list of label strings for initial setting of visible=False, any order
legend_out: boolean, True puts legend outside, False keeps legend inside
Returns
-------
p: Bokeh Figure object
'''
valid_stations = []
valid_labels = []
valid_colors = []
for station, label in zip(station_list, label_list):
if not station.empty: # check for empty dataframes
valid_stations.append(station)
valid_labels.append(label)
valid_colors.append(color_dict[label])
cds = create_cds(valid_stations, valid_labels, 'air_temp')
p = figure(
title="Air Temp",
name="airtemp_fig",
x_axis_type='datetime',
x_range = (start,end),
y_axis_label='°F',
y_range = (0,1),
width=width, height=height,
tools=tools,
)
legenddict={}
items=[]
tooltips=[("Date", "@Date_hover")]
for color, label in zip(valid_colors, valid_labels):
legenddict[label] = p.line(x='Date', y=label, line_width=2, color=color, alpha=0.8, name=label, source=cds)
items.append((label,[legenddict[label]]))
tooltips.append(("%s" % label, "@%s{int}" % label))
p.add_tools(HoverTool(
renderers=[legenddict[valid_labels[0]]],
tooltips=tooltips,
line_policy="nearest",
mode='vline'
)
)
if legend_out==True:
legend1 = Legend(
items=items[0:9],
location=(0, 15),
glyph_height=20,
glyph_width=30,
label_height=1,
#label_width=50,
label_text_baseline="middle",
label_text_font_size="10pt",
border_line_alpha=0.0,
orientation="horizontal",
padding=0, #only applies when border visible
spacing=15,
label_standoff=2,
#margin=10
)
legend2 = Legend(
items=items[9:],
location=(0, 10),
glyph_height=20,
glyph_width=30,
label_height=1,
#label_width=50,
label_text_baseline="middle",
label_text_font_size="10pt",
border_line_alpha=0.0,
orientation="horizontal",
padding=0, #only applies when border visible
spacing=15,
label_standoff=2,
margin=0
)
p.add_layout(legend1, 'below')
p.add_layout(legend2, 'below')
p.legend.click_policy="hide"
else:
legend = Legend(
items=items,
location='top_left'
)
p.add_layout(legend)
p.legend.click_policy="hide"
for x in hide_list: # go through stations on the hide_list
if p.select_one({'name':'%s' % x}): # check if the line glyph is present
p.select_one({'name':'%s' % x}).visible = False
return p