Search code examples
pythonjupyter-notebookholoviews

Mute/deactivate certain data series by default/programmatically in Holoviews Overlay


I'm plotting multiple (many) curves on the same axes using hv.Overlay and hv.Curve in a Jupyter notebook. In the resulting plot I'm mainly interested in a few of the curves. For highlighting, I can deactivate all curves but a few by clicking on the corresponding legend items (as shown in the plot below).

Question: Is there a way to do this programmatically, such that the resulting plot has some data series deactivated by default? I was thinking of something along the lines of hv.Curve(..., active=False). I don't consider lighter colors an option, since I would still like to have the possibility to activate any given data series.

import holoviews as hv
import pandas as pd
import numpy as np

np.random.seed(2)
df = pd.DataFrame({"x": sorted(list(range(9)) * 3),
                   "key": ["a", "b", "c"] * 9,
                   "val": np.random.randn(27)})

hv.Overlay([hv.Curve(df.query("key == @key"), "x", "val", label=key) 
            for key in df.key.unique()])

Target output:

enter image description here


Solution

  • If I'm understanding the question right, using the muted option should do the trick:

    hv.Overlay([hv.Curve(df.query("key == @key"), "x", "val",label=key).opts(muted = False if key == "a" else True) 
            for key in df.key.unique()])