Bug: texttemplate and hovertemplate show inconsistent values when categoryarray is used in Heatmap
Dieses Issue hat noch niemand übernommen.
- Vorherrschende Sprache
- Python
- Sterne
- 18.8k
- Forks
- 2.8k
- Ø Merge
- 16 Std. 26 Min.
- Gemergte PRs (30 T.)
- 21
Beschreibung
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.categoryarrayis reversed, both the heatmap cells and the text (%{text}) / hover labels should display the correctly corresponding values fromz.
Actual behavior:
-
The axis ordering (
x,y) updates correctly. -
The visual placement of heatmap cells updates correctly.
-
However,
%{text}inhovertemplatestill correspond to the original unsorted order ofz. -
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
Beitragsleitfaden
Erste Schritte
- Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
- Forke das Repository und arbeite in einem Branch.
- Öffne einen Pull Request, der die Issue-Nummer nennt.
Rechercherichtung
Reproduziere das Problem mit dem minimalen Python-Beispiel unter Verwendung von Plotly 6.3.1, einschließlich des umgekehrten yaxis categoryarray. Verfolge, wie heatmap cell values, texttemplate, hovertemplate und der automatische Textkontrast nach der Kategoriensortierung neu zugeordnet werden; abgeschlossen ist die Aufgabe, wenn die angezeigten Werte und Textfarben an den neu positionierten Zellen ausgerichtet bleiben.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- python
- Bereich
- data-visualization
- Issue-Typ
- Bug
- Schwierigkeit
- 4/5
- Geschätzter Aufwand
- 3-5 Tage
- Aktivitätsstatus
- Veraltet
- Klarheit
- Größtenteils klar
- Anfängerfreundlichkeit
- 38/100