Bug: texttemplate and hovertemplate show inconsistent values when categoryarray is used in Heatmap
Nadie ha tomado este issue todavía.
- Lenguaje dominante
- Python
- Estrellas
- 18.8k
- Forks
- 2.8k
- Merge medio
- 16 h 26 min
- PR fusionados (30 d)
- 21
Descripción
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
Guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Línea de trabajo
Reproduce el problema con el ejemplo mínimo de Python usando Plotly 6.3.1, incluido el yaxis categoryarray invertido. Rastrea cómo se reasignan heatmap cell values, texttemplate, hovertemplate y el contraste de texto automático después de ordenar las categorías; se considera terminado cuando los valores mostrados y los colores del texto siguen alineados con las celdas reposicionadas.
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