Group/label for hv.Ellipse() is not working

Hi there,

I can’t get the group and label to work for Ellipse plots.

Here’s a small example. As you can see it works for the Scatter points but not for ellipses.

Further, I’d like to pair each ellipse with its central point under one label so that clicking on the corresponding label in the legend toggles a particular point and its halo in and out together.

Any tip is appreciated.

points = hv.Scatter((1,1), group='Points', label='P1') * hv.Scatter((4,2.2), group='Points', label='P2')
ellipses = hv.Ellipse(1,1,(1,0.5),group='Ellipse',label="E1") * hv.Ellipse(4,2.2,(1,0.5),group='Ellipse',label="E2")
overlay_plots = hv.Overlay(ellipses + points).opts(legend_position="top_left")

image

I think annotations, like Ellipses, legends are turned off by default, so all you need to do is turn them on.

import holoviews as hv

hv.extension("bokeh")

ellipses = hv.Ellipse(1, 1, (1, 0.5), group="Ellipse", label="E1").opts(
    show_legend=True, color="blue"
) * hv.Ellipse(4, 2.2, (1, 0.5), group="Ellipse", label="E2").opts(show_legend=True, color="red")
ellipses

Admittedly, this was hard to find, so if you’re willing, do you mind improving the docs on HoloViews GitHub?

1 Like

Thanks a lot! It answered my first question, and yes I can try to improve documentation.

Any tip on my second question?

Have you tried group

Yes. As you can see in the code that I’d shared, I’m using group. I’m not sure how it can help though. Could you elaborate more? Thanks

group + show_legend?

Ah, I see. Yes, I’ve done that.
That way, I get a set of ellipses and a set of dots in the legend. I want to have one element in the legend per a pair of ellipse and the point that I put in its center. Another thing that I like to do is when I click on the item in the legend, the pair, both ellipse and its center get dim.

Make the labels the same.

import holoviews as hv

hv.extension("bokeh")

points = hv.Scatter((1,1), group='Points', label='P1') * hv.Scatter((4,2.2), group='Points', label='P2')
ellipses = hv.Ellipse(1,1,(1,0.5),group='Ellipse',label="P1").opts(show_legend=True) * hv.Ellipse(4,2.2,(1,0.5),group='Ellipse',label="P2").opts(show_legend=True)
overlay_plots = hv.Overlay(ellipses + points).opts(legend_position="top_left")

overlay_plots

1 Like

You are amazing, @ahuang11 ! I’m learning a lot from you.

I know, you’ve already answered my original questions.
I’ve more questions on this topic as my project is evolving. Let me know if I should mark this post as Solved and start a new one. :pray:

I needed to fill in the ellipses with color. That’s why I had to bring hv.Polygons in. Now, I want to do all of this for polygons. The problem is that polygons are working with a set of ellipses, and the group and label doesn’t carry over from an ellipse to its corresponding polygon. Neither I’m able to set labels for a “set” of polygons. How can I pair a point with a polygon and switch that pair in and out by clicking on their corresponding label in the legend?

ellipses = [
   {("x", "y") : hv.Ellipse(1,1,(1,0.5),group='Ellipse',label="P1").opts(show_legend=True) }
   {("x", "y") : hv.Ellipse(4,2.2,(1,0.5),group='Ellipse',label="P2").opts(show_legend=True)}
]
polygons = hv.Polygons(ellipses, group="Ellipse")