plotly / plotly/plotly.py

Bug: leftover xaxis entries when toggling between buttons

Abierto
#4,849 2 comentarios 0 reacciones 0 asignados Ver en GitHub

Nadie ha tomado este issue todavía.

Lenguaje dominante
Python
Estrellas
18.8k
Forks
2.8k
Merge medio
16 h 26 min
PR fusionados (30 d)
21

Descripción

Minimum Working Example (MWE):

import plotly.graph_objects as go
from plotly.subplots import make_subplots

# Data
option1_x = ['A', 'B', 'C']
option1_y1 = [1, 3, 2]
option1_y2 = [2, 4, 3]

option2_x = ['B', 'D', 'E']
option2_y1 = [2, 1, 4]
option2_y2 = [3, 2, 5]

# Create subplots
fig = make_subplots(rows=2, cols=1, shared_xaxes=True, subplot_titles=("y1", "y2"))

# Add traces for option1
fig.add_trace(go.Bar(x=option1_x, y=option1_y1, name="option1_y1"), row=1, col=1)
fig.add_trace(go.Bar(x=option1_x, y=option1_y2, name="option1_y2"), row=2, col=1)

# Add traces for option2
fig.add_trace(go.Bar(x=option2_x, y=option2_y1, name="option2_y1"), row=1, col=1)
fig.add_trace(go.Bar(x=option2_x, y=option2_y2, name="option2_y2"), row=2, col=1)

# Initially set option1 visible and option2 invisible
for trace in fig.data:
    trace.visible = False
fig.data[0].visible = True  # y1 option1
fig.data[1].visible = True  # y2 option1

# Add buttons
fig.update_layout(
    updatemenus=[
        {
            "type": "buttons",
            "buttons": [
                {
                    "label": "option1",
                    "method": "update",
                    "args": [
                        {"visible": [True, True, False, False]},  # Show only option1 traces
                    ]
                },
                {
                    "label": "option2",
                    "method": "update",
                    "args": [
                        {"visible": [False, False, True, True]},  # Show only option2 traces
                    ]
                }
            ],
            "showactive": True,
        }
    ],
)

fig.show()

Image

Toggling to option2, we can see the C xaxis entry (from option1) still showing (even with no data for it):

Image

This seems to only be an issue with subplots, and when the traces of different options have some xaxis labels in common (in this case B).

Guía de contribución

Abrir la guía de contribución

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Línea de trabajo

Comienza ejecutando el MWE de Python proporcionado y alternando entre los botones option1 y option2 en la figura de subplots. Inspecciona cómo se conservan las entradas compartidas del eje x cuando se ocultan las traces y las opciones comparten la etiqueta B. Se considera terminado cuando al cambiar a option2 ya no se muestra la entrada C del eje x que quedó de option1.

Escrito por el modelo de indexación a partir del texto del issue.

Evaluación

Stack tecnológico
python
Área
data-visualization
Tipo de issue
Error
Dificultad
3/5
Tiempo estimado
1-2 días
Estado de actividad
Activo
Claridad
Bastante claro
Aptitud para principiantes
55/100

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.