Keverly
Keverly

Reputation: 528

Bokeh HoverTool not working with multi_line

I'm banging my head on this one.

Bokeh's multip_line and HoverTool don't seem to want to play nice with each other. My issue is similar to this one: multi_line hover in bokeh. (side note: I've tried the solution code from that question and it's not working for me, which is probably not a good sign.)

I have my own reproducible example code here, condensed from a heatmap-like plot I'm working on:

from bokeh.plotting import figure, output_file, show
from bokeh.models.mappers import LinearColorMapper
from bokeh.models import ColumnDataSource, ColorBar, HoverTool

output_file("heatmap.html")

p = figure(title="multi_line hover failure example")
p.add_tools(HoverTool(
    show_arrow=False,
    line_policy="nearest",
    tooltips=[
        ("color", "@color"),
        ("name", "@name")
    ]))

patch_xs = [[1, 2, 2, 3], [4, 5, 6, 5], [5, 5, 8, 8]]
patch_ys = [[1, 2, 4, 1], [3, 4, 3, 2], [5, 8, 8, 5]]
patch_colors = [1, 2, 3]
patch_names = ['robert', 'quinn', 'jessy']

line_xs = [[1, 2, 2, 3], [4, 5, 6, 5], [5, 5, 8, 8]]
line_ys = [[-1, -2, -4, -1], [-3, -4, -3, -2], [-5, -8, -8, -5]]
line_colors = [-1, -2, -3]
line_names = ['karen', 'louise', 'charles']

mapper = LinearColorMapper(
    palette='Turbo256',
    low=min(patch_colors + line_colors),
    high=max(patch_colors + line_colors),
)

# patches included to confirm that hover is working
# commenting this out does not make hover work
p.patches('xs', 'ys', line_width=1,
          color={'field': 'color', 'transform': mapper},
          source=ColumnDataSource(dict(
              xs=patch_xs,
              ys=patch_ys,
              color=patch_colors,
              name=patch_names
          ))
          )

p.multi_line('xs', 'ys', line_width=8,
             color={'field': 'color', 'transform': mapper},
             source=ColumnDataSource(dict(
                 xs=line_xs,
                 ys=line_ys,
                 color=line_colors,
                 name=line_names
             )))

p.add_layout(
    ColorBar(
        color_mapper=mapper,
        location=(0, 0)
    ),
    'left')

show(p)

My code produces the graph below, in which the hover tool works fine for the filled in shapes (as can be seen in the screen shot) but not the lines. Trust me, I've tried mousing all over the lines like a deranged Aladdin trying to coax a genie to come out of them.

Bokeh multi_line patch showing hover text

Removing the filled in shapes (patches) does not fix it so a left them in to show how the hover tool should be working.

Funnily enough, according to the documentation (https://docs.bokeh.org/en/latest/docs/reference/models/tools.html#bokeh.models.tools.HoverTool) the HoverTool does not work with patches but does work with multi_line. (perhaps it has something to do with using glyphs instead of figure elements?)

Any help would be appreciated

Upvotes: 1

Views: 294

Answers (1)

Eugene Pakhomov
Eugene Pakhomov

Reputation: 10727

It's a bug. It was fixed in this commit and should be available in Bokeh 2.3.

Alternatively, you could try Bokeh 2.1 - IIRC it was working for me there.

Upvotes: 1

Related Questions