Open mattviguier opened 10 months ago
+1 for this issue. Also in 5.19.
I added another example below. The expected behavior works for the traces group; you click it and both traces turn off even though only one trace is actually in the legend. For the shapes, if you click the group, only the first shape turns invisible.
import plotly.graph_objects as go
# Make example traces.
traces = []
for i in range(2):
trace = go.Scatter(
x=[i, i + 1],
y=[i, i + 1],
name=f'Traces Group',
legendgroup='traces_group',
showlegend=True if i == 0 else False
)
traces.append(trace)
# Make example shapes.
shapes = []
for i in range(2):
shape = dict(
type='rect',
x0=i,
x1=i+1,
name='Shapes Group',
showlegend=True if i == 0 else False,
)
shapes.append(shape)
# Make and show figure.
fig = go.Figure(
traces,
layout=dict(shapes=shapes),
)
fig.show()
Base figure:
Toggle trace group:
Toggle shape group:
Indeed, this looks like a bug. Thank you for reporting, @mattviguier and @mboll. @archmoj here's is the codepen. Let me know if we should transfer this to Plotly.js
Yes please transfer it to plotly.js. Thank you! @Coding-with-Adam
When adding a shape to a legendgroup with showlegend=False, he does not toggle the visibility when clicking in the legend which is inconsistent with the expected behaviour of traces.
Here is the code to reproduce the graph. Plotly version:
5.17.0
Full graph:
Trace legend group toggle:
Shape legend group toggle:
![graph_vline_hidden](https://github.com/plotly/plotly.py/assets/66131812/6f4afadc-dfcb-4a4d-aa15-e37c3e37db2a)