How do I divide legend entries by group?

If you specify both groups and labels for your elements, it seems that the automatically generated legend only uses the labels to construct the entries, even if the groups have different styling:

import numpy as np
import holoviews as hv
from holoviews import opts

hv.extension("bokeh", case_sensitive_completion=True)

xs = np.linspace(0, 100)
a1 = hv.Curve((xs, xs), group="a", label="1")
a2 = hv.Curve((xs, 2 * xs), group="a", label="2")
b1 = hv.Curve((xs, -xs), group="b", label="1")
b2 = hv.Curve((xs, 2 * (-xs)), group="b", label="2")

overlay = a1 * a2 * b1 * b2

overlay.opts(
    opts.Curve("a", line_color="green"),
    opts.Curve("b", line_dash="dashed"),
)

In the above example, the legend entry for ‘1’ is a green line overlaid with blue dashes, and for ‘2’ is a green line overlaid with red dashes. It would be less confusing if the legend was split into four entries labeled “a, 1”, etc. Is this possible?

1 Like

That is a good question, I am also interested if there is an way to achieve that.