plotly / plotly/plotly.py

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

Đang mở
#5,385 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Chưa có ai nhận issue này.

Ngôn ngữ chính
Python
Star
18.8k
Fork
2.8k
Merge trung bình
16 giờ 26 phút
Pull request đã merge (30 ngày)
21

Mô tả

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

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Hướng nghiên cứu

Tái hiện vấn đề bằng ví dụ Python tối thiểu sử dụng Plotly 6.3.1, bao gồm yaxis categoryarray bị đảo ngược. Theo dõi cách heatmap cell values, texttemplate, hovertemplate và độ tương phản văn bản tự động được ánh xạ lại sau khi sắp xếp danh mục; hoàn tất khi các giá trị được hiển thị và màu văn bản vẫn căn chỉnh với các ô đã được định vị lại.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Đánh giá

Công nghệ
python
Lĩnh vực
data-visualization
Loại issue
Lỗi
Độ khó
4/5
Thời gian dự kiến
3-5 ngày
Mức độ hoạt động
Đình trệ
Độ rõ ràng
Khá rõ ràng
Mức phù hợp với người mới
38/100

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.