plotly / plotly/plotly.py

Bug: texttemplate and hovertemplate show inconsistent values when categoryarray is used in Heatmap

Aperta
#5,385 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

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

Descrizione

Minimal working example:
import plotly.graph_objects as go

z = [
    [1, None, 30, 50, 1],
    [20, 1, 60, 80, 30],
    [30, 60, 1, -10, 20]
]
x = ['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday']
y = ['Morning', 'Afternoon', 'Evening']

fig = go.Figure(
    data=go.Heatmap(
        z=z,
        x=x,
        y=y,
        text=z,
        texttemplate='%{x}<br>%{y}<br>%{text}',
        hovertemplate='%{x}<br>%{y}<br>%{text}<extra></extra>',
    )
)

# Reverse y-axis order
fig.update_layout(yaxis={'categoryarray': y[::-1]})
fig.show()
Expected behavior:
  • When the yaxis.categoryarray is reversed, both the heatmap cells and the text (%{text}) / hover labels should display the correctly corresponding values from z.
Actual behavior:
  • The axis ordering (x, y) updates correctly.

  • The visual placement of heatmap cells updates correctly.

  • However, %{text} in hovertemplate still correspond to the original unsorted order of z.

  • This leads to mismatched hover and text values after sorting by category.

Example:

After reversing the y axis, the heatmap looks right, but hovering over a cell labeled "Morning / Monday" still shows the value corresponding to "Evening / Monday" from the original order.

Additional note (text color rendering issue)

I also noticed that the text color changes incorrectly after sorting:

In the unsorted heatmap, cells like “Thursday / Evening” show white text on a dark blue background, which is legible and consistent.

After applying the categoryarray sort, the same cell (now visually repositioned) starts showing almost black text on the same dark background, making it nearly invisible.

This suggests that the automatic contrast adjustment for text color (based on cell background) may not update properly after the category sorting.

Version info
plotly.__version__
# 6.3.1
Image

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

Riproduci il problema con l'esempio Python minimo usando Plotly 6.3.1, incluso il yaxis categoryarray invertito. Traccia come heatmap cell values, texttemplate, hovertemplate e il contrasto automatico del testo vengono rimappati dopo l'ordinamento delle categorie; l'attività è completata quando i valori visualizzati e i colori del testo rimangono allineati con le celle riposizionate.

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.