plotly / plotly/plotly.py

Multiple legends are not independent in their placement and placement is not consistent

Abierto
#4,367 0 comentarios 0 reacciones 0 asignados Ver en GitHub

Nadie ha tomado este issue todavía.

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

Descripción

I am currently experimenting with the new-ish multi-legend feature. Unfortunately I seem to have stumbled across a case in which the legends are not behaving independently even though it is not clear why.

The following code demonstrates this:

from copy import deepcopy
import plotly.graph_objects as go

error_fig = {
    'data': [
        {
            'legend': 'legend2',
            'showlegend': True,
            'type': 'scatter',
            'x': [0, 1],
            'xaxis': 'x2',
            'y': [0, -1],
            'yaxis': 'y2'
        },
        {
            'legend': 'legend3',
            'showlegend': True,
            'type': 'scatter',
            'x': [0, 1],
            'xaxis': 'x3',
            'y': [0, 1],
            'yaxis': 'y3'
        },
        {
            'legend': 'legend3',
            'showlegend': True,
            'type': 'scatter',
            'x': [0, 1],
            'xaxis': 'x3',
            'y': [0, -1],
            'yaxis': 'y3'
        },
        {
            'legend': 'legend3',
            'showlegend': True,
            'type': 'scatter',
            'x': [0, 1],
            'xaxis': 'x3',
            'y': [0, 1],
            'yaxis': 'y3'
        },
        {
            'legend': 'legend3',
            'showlegend': True,
            'type': 'scatter',
            'x': [0, 1],
            'xaxis': 'x3',
            'y': [0, 1],
            'yaxis': 'y3'
        }
    ],
    'layout': {
        'legend2': {
            'orientation': 'v',
            'visible': True,
            'x': 0.515,
            'xanchor': 'left',
            'xref': 'paper',
            'y': 0.3,
            'yanchor': 'top',
            'yref': 'paper'
        },
        'legend3': {
            'entrywidth': 0.2,
            'entrywidthmode': 'fraction',
            'orientation': 'h',
            'visible': True,
            'x': 0.95,
            'xanchor': 'left',
            'xref': 'paper',
            'y': 1.0,
            'yanchor': 'top',
            'yref': 'paper'
        },
        'xaxis2': {'anchor': 'y2', 'domain': [0, 0.5]},
        'xaxis3': {'anchor': 'y3', 'domain': [0.45, 0.95]},
        'yaxis2': {'anchor': 'x2', 'domain': [0, 0.3]},
        'yaxis3': {'anchor': 'x3', 'domain': [0.7, 1.0]}
    }
}


correct_fig = deepcopy(error_fig)
correct_fig["layout"]["legend3"]["x"] = 1

fig_correct = go.Figure(correct_fig)
fig_correct.show()

fig_error = go.Figure(error_fig)
fig_error.show()

Where fig_correct produces this output upon png-download (The issue also exists in interactive mode with varying severity based on screen size):
correct

fig_error produces this:
error

Which for me makes no sense as the only change that occurred was the placement of legend3 along x. I would therefore not expect legend2 to move. Additionally, for me it does not make any sense, why any large movement should occur at all, as I only changed the x-coordinate of legend3 by 0.05 .

For me the Issue only occurs when using "orientation": "h".


I am on Python 3.11.1
My pip dump:

Package    Version
---------- -------
packaging  23.1
pip        22.3.1
plotly     5.17.0
setuptools 65.5.0
tenacity   8.2.3

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

Comience ejecutando la reproducción de Python proporcionada con Plotly 5.17.0 y compare los diseños de multileyendas horizontales en el modo interactivo y en la salida PNG. No se especifica ningún archivo fuente ni prueba, así que siga los puntos de entrada de colocación de leyendas y renderizado del diseño a partir de la reproducción; se considera terminado cuando mover legend3 ya no mueve inesperadamente legend2 ni provoca un desplazamiento desproporcionado.

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
4/5
Tiempo estimado
3-5 días
Estado de actividad
Estancado
Claridad
Bastante claro
Aptitud para principiantes
38/100

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.