Search code examples
pythonholoviews

Setting opts of individual Elements in holoviews Holomaps


Given a Holomap-like object (HoloMap, NdOverlay, ...) created by grouping by an additional kdim, is there a way to access specific sub-elements for individual styling? Given a HoloMap p:

p = hv.Dataset(([0, 1], [2, 2], ['a', 'b']), ['x', 'y', 'z']
              ).to(hv.Points, groupby='z')

is it possible to add individual style opts for z='a', z='b'? I've tried the group.label syntax but that didn't work.

If not, I reckon I would have to create a dictionary of the Elements and pass the group label explicitly?

hv.HoloMap({z_value: hv.Points(..., group=z_value) for z_value in ...})

Solution

  • You could index into the HoloMap and use the .opts method to apply the options without cloning, e.g.:

    p = hv.Dataset(([0, 1], [2, 2], ['a', 'b']), ['x', 'y', 'z']
              ).to(hv.Points, groupby='z')
    p['a'].opts(color='red')
    p['b'].opts(color='blue')
    p