Interactive legend does not work well if you use the same name for all glyphs

Hi folks,

Trying to help here.

I was reading about Interactive legends and I see a behavior that I think is an error.
If you use the same name for 3 glyphs what you get in the legend is just 1, if you click over it and you have activated “mute” or “hide” you see that all the 3 glyphs are hiden at the same time.

I think if I show 3 glyphs there should be 3 leyends, even if the name is the same because the colour allows me to see which one I want to select.


@pedro_rodriguez That is the intended behaviour when using the convenience API for legends. The reason for that is to be able to combine the glyphs from e.g. “line-with-scatter” plots into one legend:

However, you can definitely accomplish the result you describe, you will just have to construct manual legend items:

Can you provide an example where using the same legend for two lines is useful?

I mean in this case you used three different legends: sin (x) , 2 sin (x) and 3 sin (x)

@pedro_rodriguez I never said that using the same legend_label for two different line glyphs was useful, in fact I expect it is not useful. What I explained was why the high-level legend_label “combines” glyphs the way it does (to support examples like the one I posted) and also linked to docs for how to use the lower-level legend manually if you wanted something different than that.

But since we seem to be miscommunicating, I will stop speculating at this point and ask that you supply a Minimal Reproducible Example so that we can focus on actual code without any ambiguity or guessing about intentions.

1 Like

Hi Bryan,

Thanks for your reply and sorry for being late.

I know this is a silly thing. It simply surprised me to see that if you use the same “legend_label” in diferent glyphs Bokeh decides automatically to join all the legends in just one.

1 Like