How can add Shapes legend

Hi all

I have added some shapes to my figure:

import plotly.graph_objs as go
fig = go.Figure()

for i in range(5):
    fig.add_shape(type="circle", xref="x", yref="y", x0=i*5, y0=-1, x1=i*5+4, y1=2,name='shape')

fig.update_xaxes(title_text='x',range=[0, 25],)

fig.update_layout(showlegend=True)

fig.show()

how can I add legend for them? [for example ‘circles’ ]

It is not possible to add legend items to shapes, unfortunately. Do you want it to be able to control the visibility of each shape or just “to give them a label”? There are workarounds for both, I think…

1 Like

dear @jlfsjunior
Thanks for your guidance
I don’t know how did you read my mind???
Exactly I want to make all the shapes as a group of shapes and with a click on legend (or something like that) hide them!

You can adapt this example with custom buttons in this case:

1 Like

Again Thanks @jlfsjunior

I can draw circles with scatter and then I have many options in this way (like legend and …) . I think plotly tries to force users to use scatter or 3Dscatter instead of all other methods. Am I thinking correct?

I understand what you are saying by “forcing”. Perhaps it is better to put this way: shapes are for annotation purposes, not to display data.

That said, I don’t see how you can make a circle using scatter: you can make a polygon by connect N points, but a circle needs N \to \infty

1 Like

By now this is supported: