Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cannot hide all shape entries in a group by its legend #4896

Open
Honghe opened this issue Nov 21, 2024 · 0 comments
Open

cannot hide all shape entries in a group by its legend #4896

Honghe opened this issue Nov 21, 2024 · 0 comments
Labels
bug something broken P3 backlog

Comments

@Honghe
Copy link

Honghe commented Nov 21, 2024

Envivonment:

  • OS: Windows 10
  • Plotly.py: 5.24.1
  • plotly.js: 2.35.2

Bug recording:

Video.mp4

Bug code:

import plotly.graph_objects as go

fig = go.Figure()

fig.add_shape(
    type="line",
    xref="x",
    yref="y",
    x0=4,
    y0=0,
    x1=8,
    y1=1,
    line=dict(
        color="LightSeaGreen",
        width=3,
    ),
    legendgroup="group",  # this can be any string, not just "group"
    name="first legend group",
    showlegend=True,
)
fig.add_shape(
    type="line",
    xref="paper",
    yref="paper",
    x0=0,
    y0=0,
    x1=0.5,
    y1=0.5,
    line=dict(
        color="DarkOrange",
        width=3,
    ),
    legendgroup="group",  # this can be any string, not just "group"
    name="first legend group B",
    showlegend=False,
)

fig.show()

Reference:
https://plotly.com/python/legend/#grouped-legend-items Says: You can also hide entries in grouped legends, preserving the grouped show/hide behaviour. This is what Plotly Express does with its legends.

Excepted(The demo in the document):

Video.mp4

The demo Code in the document:

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"
    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"),
    showlegend=False,
))

fig.add_trace(go.Scatter(
    x=[1, 2, 3],
    y=[4, 9, 2],
    legendgroup="group2",
    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"),
    showlegend=False
))

fig.update_layout(title=dict(text="Try Clicking on the Legend Items!"))
fig.show()
@Honghe Honghe changed the title Can't hide all shape entries in a group by its legend. Bug: Can't hide all shape entries in a group by its legend. Nov 22, 2024
@gvwilson gvwilson changed the title Bug: Can't hide all shape entries in a group by its legend. cannot hide all shape entries in a group by its legend Nov 26, 2024
@gvwilson gvwilson added bug something broken P3 backlog labels Nov 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug something broken P3 backlog
Projects
None yet
Development

No branches or pull requests

2 participants