Skip to content

legend_groupclick="toggleitem" not working #3488

Closed
@janosh

Description

@janosh

Adding fig.update_layout(legend_groupclick="toggleitem") (as documented) to the grouped legend items example does not affect legend click behavior. With or without setting to "toggleitem", the whole group is toggled when clicking any item in the legend. Using plotly==5.4.0.

import plotly.graph_objects as go


fig = go.Figure()

fig.add_trace(
    go.Scatter(
        x=[1, 2, 3],
        y=[2, 1, 3],
        legendgroup="group",  # this can be any string, not just "group"
        legendgrouptitle_text="First Group Title",
        name="first legend group",
        mode="markers",
        marker=dict(color="Crimson", size=10),
    )
)

fig.add_trace(
    go.Scatter(
        x=[1, 2, 3],
        y=[2, 2, 2],
        legendgroup="group",
        name="first legend group - average",
        mode="lines",
        line=dict(color="Crimson"),
    )
)

fig.add_trace(
    go.Scatter(
        x=[1, 2, 3],
        y=[4, 9, 2],
        legendgroup="group2",
        legendgrouptitle_text="Second Group Title",
        name="second legend group",
        mode="markers",
        marker=dict(color="MediumPurple", size=10),
    )
)

fig.add_trace(
    go.Scatter(
        x=[1, 2, 3],
        y=[5, 5, 5],
        legendgroup="group2",
        name="second legend group - average",
        mode="lines",
        line=dict(color="MediumPurple"),
    )
)

# No effect from this line
fig.update_layout(legend_groupclick="toggleitem")

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions