Open
Description
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
import plotly.graph_objects as go
from plotly import data
from plotly.subplots import make_subplots
df = data.gapminder()
fig = make_subplots(
rows=2,
cols=1,
)
filtered_data = df.loc[(df.country.isin(["Germany"]))]
fig.add_trace(
go.Scatter(
x=filtered_data.year,
y=filtered_data.lifeExp,
name="Germany",
legend="legend",
legendgroup="EU",
),
row=1,
col=1,
)
filtered_data = df.loc[(df.country.isin(["United Kingdom"]))]
fig.add_trace(
go.Scatter(
x=filtered_data.year,
y=filtered_data.lifeExp,
name="United Kingdom",
legendgroup="not EU",
),
row=1,
col=1,
)
filtered_data = df.loc[(df.country.isin(["France"]))]
fig.add_trace(
go.Scatter(
x=filtered_data.year,
y=filtered_data.lifeExp,
name="France",
legendgroup="EU",
showlegend=False,
),
row=2,
col=1,
)
fig.add_hline(
y=72,
line_dash="dot",
label=dict(
text=f"vline1",
textposition="end",
),
name="vline",
legendgroup="vline_group",
showlegend=True,
row=1,
col=1,
)
fig.add_hline(
y=72,
line_dash="dot",
label=dict(
text=f"vline2",
textposition="end",
),
name="vline2",
legendgroup="vline_group",
showlegend=False,
row=2,
col=1,
)
fig.show()
Full graph:
Trace legend group toggle:
Shape legend group toggle: