plotly / plotly/plotly.py

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

Aperta
#4,367 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

bug P3
Lingua principale
Python
Stelle
18.8k
Fork
2.8k
Merge medio
16h 26m
PR unite (30g)
21

Descrizione

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

Guida per i contributori

Apri la guida per i contributori

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Direzione di ricerca

Iniziate eseguendo la riproduzione Python fornita con Plotly 5.17.0 e confrontate i layout orizzontali con più legende in modalità interattiva e nell’output PNG. Non è indicato alcun file sorgente o test, quindi tracciate dalla riproduzione i punti di ingresso per il posizionamento delle legende e il rendering del layout; il lavoro è concluso quando lo spostamento di legend3 non sposta più inaspettatamente legend2 né causa uno spostamento sproporzionato.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
python
Ambito
data-visualization
Tipo di issue
Bug
Difficoltà
4/5
Tempo stimato
3-5 giorni
Stato di attività
Ferma
Chiarezza
Abbastanza chiara
Idoneità per principianti
38/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.