Automargins cause imshow figure to jump around and change pixel size and labels spacing
Dieses Issue hat noch niemand übernommen.
Bewertung
- Schwierigkeit
- 4/5
- Geschätzter Aufwand
- 3-5 Tage
- Anfängerfreundlichkeit
- 35/100
- Issue-Typ
- Bug
- Klarheit
- Größtenteils klar
- Aktivitätsstatus
- Veraltet
- Tech-Stack
- python
- Bereich
- data-visualization
Rechercherichtung
Beginnen Sie mit der bereitgestellten Python px.imshow-Reproduktion, vergleichen Sie automargin=True mit dem manuellen Rand-Workaround und überprüfen Sie das automargin-Verhalten der x- und y-Achsen. Verfolgen Sie die für update_xaxes und update_yaxes verwendete Berechnung oder Anwendung von automargin. Als erledigt gilt die Aufgabe, wenn Heatmaps unterschiedlicher Größe ohne manuelle Ränder eine konsistente Pixelgröße, Positionierung und Beschriftungsabstände beibehalten.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Beschreibung
I wasn't sure if this was a bug initially so I provided a reproducible example and closer description in the forum.
Briefly, with automargin=False, heatmaps of different figure sizes have the same pixel size:

Setting automargin=True creates figures with widely different pixel sizes and shifts where the figure appear and its whitespace (with more than just the label length):

The jumping around behavior and inconsistent pixel sizes both seem to come from a bug in how the automargins are calculated or applied. A workaround is to set automargin=False and then manually specifying how much space is needed for the labels in the margin dictionary, e.g. margin=dict(t=100, b=0, l=80, r=0) and pad the overall figure size with these numbers, e.g. height = 100 + cut * 30.
It seems like the automargins are not correctly adding their label padding to the overall figure size, so that would be my suggestion for what could be a possible solution here.
Example code:
import plotly.express as px
import numpy as np
import pandas as pd
np.random.seed(20934)
img = np.random.rand(200, 200)
for cut in [10, 50]:
fig = px.imshow(
img[:cut, :cut],
height=cut * 30,
width=cut * 30,
x = [''.join(np.random.choice(list('qwertyuioplkjhgfdsazxcvbnm,.;[098765432'), np.random.choice(40))) for x in range(cut)],
y = [''.join(np.random.choice(list('qwertyuioplkjhgfdsazxcvbnm,.;[098765432'), np.random.choice(40))) for x in range(cut)],
)
fig.update_layout(
coloraxis_showscale=False,
margin=dict(t=0, b=0, l=0, r=0),
xaxis_nticks=cut + 1,
yaxis_nticks=cut + 1,
).update_xaxes(
automargin=False,
).update_yaxes(
automargin=False,
)
fig.show()
- Vorherrschende Sprache
- Python
- Sterne
- 18.8k
- Forks
- 2.8k
- Ø Merge
- 16 Std. 26 Min.
- Gemergte PRs (30 T.)
- 21
Beitragsleitfaden
Erste Schritte
- Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
- Forken Sie das Repository und arbeiten Sie in einem Branch.
- Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.
Mehr aus plotly/plotly.py
-
P3 size: 1 task
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 72/100
-
bug P1
Schwierigkeit 1/5 Unter einer Stunde Anfängerfreundlichkeit 68/100
-
feature P3
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 62/100
-
feature P3
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 72/100
-
Schwierigkeit 3/5 1-2 Tage Anfängerfreundlichkeit 35/100
Alle Issues in plotly/plotly.py
Ähnliche Issues
-
link-check link-check:sphinx-theme
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 72/100
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 65/100
qgis/QGIS-Documentation#11275 ·
-
bug priority:normal ready-for-dev
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 88/100
OpenHands/extensions#626 · 1 Kommentar ·
-
Schwierigkeit 1/5 Unter einer Stunde Anfängerfreundlichkeit 90/100
CSCfi/sd-search-api#39 ·
-
Schwierigkeit 1/5 Unter einer Stunde Anfängerfreundlichkeit 90/100