Skip to content

Annotated Heatmap: automatic font color #485

Open
@u3r

Description

@u3r

Given an annotated heatmap I would expect the cell text to contrast with the cell color.
(Not doing so leads to the readability issues in the current documentation/example of Annotated Heatmap: https://plotly.net/simple-charts/heatmaps.html)

A good contrast is shown and discussed on the python side of plotly: plotly/plotly.py#1300

When I did not find a way to do that, I looked at the implementation of AnnotatedHeatmap.
Here the configuration of the annotations is not dependent on the actual cell values - I could only apply a workaround of setting a background color.
I did not find/check the actual layouting step if there is a better place to compute correct font color.

Activity

kMutagene

kMutagene commented on Apr 7, 2025

@kMutagene
Collaborator

Hey @u3r, thanks for reporting this.

Our methods have no access to the computed colors on the used colorscale. Colors are assigned by the plotly.js renderer in the browser. This means that for automatic font color, we would need a full implementation of all pre-defined color scales, as well as custom colorscales that can return computed color values based on the range of data. This is error prone, e.g. when the base plotly.js changes/adds a named color scale, we always have to fully implement it as well - not an ideal solution and i wonder how the python lib does it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @u3r@kMutagene

        Issue actions

          Annotated Heatmap: automatic font color · Issue #485 · plotly/Plotly.NET