plotly / plotly/plotly.py

`groupclick="toggleitem"` Does Not Work Consistently Across Subplots in Plotly

Ouverte
#4,946 0 commentaires 0 réactions 0 personnes assignées Voir sur GitHub

Personne n'a encore pris cette issue.

bug P3
Langage dominant
Python
Étoiles
18.8k
Forks
2.8k
Merge moyen
16 h 26 min
PR mergées (30 j)
21

Description

Description

When using the groupclick="toggleitem" parameter in Plotly with subplots, the toggling behavior for legend items only applies to traces in the first subplot. Traces in other subplots are not affected as expected, even when the legendgroup attribute is set consistently for all relevant traces.

This issue breaks the intended behavior of groupclick="toggleitem" for figures with subplots, where users would expect the toggling of a legend item to apply uniformly across all traces in the same legendgroup, regardless of their subplot.

Expected Behavior

Clicking a legend item with groupclick="toggleitem" should toggle the visibility of all traces in the corresponding legendgroup, including traces in subplots other than the first.

Observed Behavior

When clicking a legend item:

  • The visibility of traces is toggled only in the first subplot.

  • Traces in other subplots within the same legendgroup remain unaffected.

Minimal Reproducible Example
import plotly.graph_objects as go
from plotly.subplots import make_subplots

# Create a subplot figure
fig = make_subplots(rows=3, cols=1)

# Add traces to the first subplot
fig.add_trace(go.Scatter(x=[1, 2, 3], y=[1, 4, 9], name="Group A", legendgroup="group_a"), row=1, col=1)
fig.add_trace(go.Scatter(x=[1, 2, 3], y=[2, 4, 8], name="Group B", legendgroup="group_b"), row=1, col=1)

# Add traces to the second subplot
fig.add_trace(go.Scatter(x=[1, 2, 3], y=[1, 3, 6], name="Group A", legendgroup="group_a", showlegend=False), row=2, col=1)
fig.add_trace(go.Scatter(x=[1, 2, 3], y=[2, 5, 7], name="Group B", legendgroup="group_b", showlegend=False), row=2, col=1)

# Add traces to the third subplot
fig.add_trace(go.Scatter(x=[1, 2, 3], y=[1, 2, 3], name="Group A", legendgroup="group_a", showlegend=False), row=3, col=1)
fig.add_trace(go.Scatter(x=[1, 2, 3], y=[3, 5, 9], name="Group B", legendgroup="group_b", showlegend=False), row=3, col=1)

# Update layout with groupclick parameter
fig.update_layout(
    legend=dict(groupclick="toggleitem")
)

fig.show()

Steps to Reproduce
  1. Run the provided example code.

  2. Click on a legend item for "Group A" or "Group B."

  3. Observe that the traces in the first subplot toggle visibility as expected.

  4. Notice that traces in other subplots do not toggle visibility.

### Environment

Plotly Version: 5.24.1
Python Version: 3.11.9
Operating System: Windows 11
Browser: Edge 131.0.2903.86

Additional Notes

The issue does not occur when the groupclick parameter is omitted. The default behavior works as expected, where clicking a legend item toggles all traces in the same legendgroup across all subplots.

However, groupclick="toggleitem" is necessary for more granular control of legend interactions, and it should work consistently across subplots.

Guide de contribution

Ouvrir le guide de contribution

Par où commencer

  1. Lisez l'issue en entier, puis le guide de contribution du projet.
  2. Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
  3. Forkez le dépôt et travaillez sur une branche.
  4. Ouvrez une pull request qui référence le numéro de l'issue.

Piste de recherche

Commencez par exécuter l’exemple minimal reproductible en Python fourni avec Plotly 5.24.1 et vérifiez le comportement de la légende dans les trois subplots. Suivez le point d’entrée de l’interaction avec la légende dans le dépôt ou dans son intégration de Plotly.js, puis ajoutez une couverture pour groupclick="toggleitem" avec des groupes de légende partagés. La tâche est terminée lorsqu’un clic sur un élément de la légende applique systématiquement le changement de visibilité attendu dans chaque subplot.

Rédigé par le modèle d'indexation à partir du texte de l'issue.

Évaluation

Stack technique
python
Domaine
data-visualization
Type d'issue
Bug
Difficulté
4/5
Temps estimé
3-5 jours
Activité
À l'abandon
Clarté
Clairement spécifiée
Accessibilité débutants
52/100

Recevez les nouvelles issues par e-mail

Un résumé court des issues GitHub adaptées aux débutants.