Don't show line/scatter of category anymore when you unselect it by clicking on legend

When I click on a category in a legend, the plot adjusts by only showing that category and its markers in the plot still slightly.

How can I change that so that when I click on a category, the markers of that category are not visible at all anymore in my plot?

Sample code:

import numpy as np
import pandas as pd
import holoviews as hv
hv.extension('bokeh')
import hvplot.pandas

# create sample data
df = pd.DataFrame({
    'col1': np.random.rand(50),
    'col2': np.random.rand(50),
    'category': np.random.choice(['A', 'B'], 50)
})

# plot line
df.hvplot.scatter(x='col1', y='col2', by='category')
df.hvplot.scatter(x='col1', y='col2', by='category', muted_alpha=0)

Thanks so much! I am always surprised how much there is still to learn (and how easy the answer sometimes can be :slight_smile: )

So the solution is using option: muted_alpha=0

Setting the muted_alpha=0 still only mutes the data. What you really want is to hide the data. Hide also works for hover, while mute doesn’t (see below). In Bokeh this is possible by setting p.legend.click_policy=‘hide’. In Holoviews I didn’t find an option for this.
A workaround for hvplot, which works for me, is first converting the plot to a bokeh object first and than setting the click policy.

p=hv.render(df.hvplot.scatter(x='col1', y='col2', by='category'), backend='bokeh')
p.legend.click_policy='hide'

Would be nice if this was supported in Holoviews.

See figure for my data.


compare hide (left) with mute (right)