plotly / plotly/plotly.py

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

Aberta
#5,385 0 comentários 0 reações 0 responsáveis Ver no GitHub

Ninguém assumiu esta issue ainda.

Linguagem predominante
Python
Estrelas
18.8k
Forks
2.8k
Merge médio
16h 26min
PRs com merge (30d)
21

Descrição

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

Guia de contribuição

Abrir o guia de contribuição

Primeiros passos

  1. Leia a issue inteira e depois o guia de contribuição do projeto.
  2. Comente na issue dizendo que vai assumir — evita que duas pessoas façam o mesmo trabalho.
  3. Faça um fork do repositório e trabalhe em uma branch.
  4. Abra um pull request que referencie o número da issue.

Direção de pesquisa

Reproduza o problema com o exemplo mínimo em Python usando Plotly 6.3.1, incluindo o yaxis categoryarray invertido. Rastreie como heatmap cell values, texttemplate, hovertemplate e o contraste automático do texto são remapeados após a ordenação das categorias; considera-se concluído quando os valores exibidos e as cores do texto permanecem alinhados com as células reposicionadas.

Escrita pelo modelo de indexação a partir do texto da issue.

Avaliação

Stack de tecnologia
python
Domínio
data-visualization
Tipo de issue
Bug
Dificuldade
4/5
Tempo estimado
3-5 dias
Status de atividade
Estagnada
Clareza
Razoavelmente clara
Facilidade para iniciantes
38/100

Receba novas issues na sua caixa de entrada

Um resumo curto de issues do GitHub para quem está começando.