plotly / plotly/plotly.py

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

オープン
#5,385 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

主要言語
Python
スター
18.8k
フォーク
2.8k
平均マージ
16時間 26分
マージ済み PR(30日)
21

説明

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

コントリビューションガイド

コントリビューションガイドを開く

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

調査の方向性

逆順の yaxis categoryarray を含む、Plotly 6.3.1 を使用した最小の Python 例で問題を再現します。カテゴリの並べ替え後に、heatmap cell values、texttemplate、hovertemplate、自動テキストコントラストがどのように再マッピングされるかを追跡します。再配置されたセルに、表示値とテキストの色が引き続き対応していれば完了です。

索引モデルが issue の本文から書いたものです。

評価

技術スタック
python
領域
data-visualization
issue の種類
バグ
難易度
4/5
見積もり時間
3〜5日
活発さ
停滞
明瞭さ
おおむね明確
初心者へのやさしさ
38/100

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。