Is there a way to hide hovertool for muted datasets that have muted_alpha=0?

This is related to the ticket below on bokeh. Basically points are still selectable even after the dataset has been muted completely. Is there a way to not make hidden points selectable on the holoviews side?

  • line is set one in blue
  • offset_line is in red ==> hidden (muted_alpha=0) but still selectable

Thank you in advanced for any help!

import holoviews as hv
hv.extension("bokeh")
from holoviews import opts

df1 = pd.DataFrame({"x": [1], "y" : [1], "set": "one"})
df2 = pd.DataFrame({"x": [1], "y" : [1.001], "set": "two"})

scatter1 = hv.Scatter(data=df1, kdims="x", vdims=["y","set"], label="line")
scatter2 = hv.Scatter(data=df2, kdims="x", vdims=["y","set"], label="offset line")

overlay = hv.Overlay([scatter1, scatter2])

overlay.opts(
    opts.Overlay(
        width=800,
        height=800,
        ),
    opts.Scatter(
        tools=["hover"],
        muted_alpha=0,
        )
    )

hv.save(overlay, Path(r"C:\Users\econtrerasguzman\Desktop") / "example.html")

Try this Don't show line/scatter of category anymore when you unselect it by clicking on legend - #5 by Hoxbro

Thanks for the prompt reply, that seems to have worked! I’m new to both, would you suggest plotting through hvplot or holoviews in general?

My personal rule of thumb is if what you want to plot is in a DataFrame or xarray use hvplot, if not use holoviews. Of course the rule is always overruled by what is easiest to implement. The output of hvplot is a holoviews plot so you can always use both if needed.

in your example you can also change the overlay.opts to the following and get the same effect:

overlay.opts(
    opts.Overlay(
        legend_opts={"click_policy": "hide"},
        width=800,
        height=800,
    ),
    opts.Scatter(
        tools=["hover"],
    ),
)

cool, that’s a a much simpler way to add that click policy :slight_smile: really appreciate the help!

1 Like