Skip to content

Legendgroup visibility not consistent with shape #6929

Open
@mattviguier

Description

@mattviguier

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:
graph_visible
Trace legend group toggle:
graph_trace_hidden
Shape legend group toggle:
graph_vline_hidden

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2considered for next cyclebugsomething brokensev-2serious problem

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions