Multi_line legend click to hide single curve

Hi all,

I really need to use multi_line for my 100-or-so curves plot, otherwise it will be excruciatingly slow.
I expected to be able to turn curves on and off by clicking on legend items, as in normal line plots, but actually this affects the whole set of curves. It seems that it was not feasible as bokeh could only modulate visibility of a single (entire) glyph at a time:

but using the TapTool, as in:

actually allows you to turn on and off single lines… so maybe I’m missing something, shouldn’t if be possible to do the same from the legend, i.e. hide groups of lines by clicking on the corresponding legend entry?

What I’ve resorted to is to bypass the Bokeh “built in” legends, and instead used a widget like a checkbox group to update an index filter on the CDS driving the multiline.

Unfortunately, as I stated in the issue, it’s just not going to be feasible. The underlying internal machinery of line vs multi_line is rather different, and the mechanism that legends use to modulate glyph visibility is just not compatible with modulating “part” of a glyph.

What is your actual use case? Do you really have a legend with 100+ entries? That seems unwieldy all on its own. @gmerritt123’s suggestion of a separate widget is very sensible. Or are there actually only a handful of specific lines that you need to control? Then use line for those (to use an interactive legend) and multi_line for all the rest.

Thanks for your reply,
actually I only have 4 legend entries, so I create corresponding multiline plots and 4 corresponding legend items and the I can easily switch group of lines on and off. I was just curious because, as I said, the TapTool seem to be able to switch on an off single lines, so I assumed that visibility can be actually triggered for individual lines of a multiline plot.

Thanks again

The tap tool is doing hit-testing to determine which “row(s)” of the CDS were selected, then using those selection indices to drive the auxiliary hover_glyph etc. This is exactly the same way things work with a simple scatter plot, but in this case it is a “scatter” of (sub-)lines, But the legend just sets a simple property visible or muted on the glyph renderer, it does not know anything about indices at all, and trying to teach it would make an already complicated and hard to maintain corner of Bokeh even moreso.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.