Force show text on Nan Heatmap cells

Hi everyone, I’m making calendar heatmap and have next issue:

When some days don’t have z-values, I fill them with None. In this case, text over cells with z=None wouldn’t have text applied (day number)

Replacing None with 0 does not solve issue, as it would break a color scale and return something like this:

How can I force text to be shown on cells where z-value is None?

hi @ilazariev
:wave: welcome to the community.

This is an interesting problem. Can you share the full code with us so we can reproduce the error on our computer?

minimum example would be as follows:

import plotly.graph_objects as go

if __name__ == "__main__":
    z = [[None, None, 3], [3, 4, 3], [5, 6, None]]
    text = [[1, 2, 3], [4, 5, 6], [7, 8, 9]]
    heatmap = go.Heatmap(
        x=[0, 1, 2],
        y=[0, 1, 2],
        z=z,
        texttemplate="%{text}",
        text=text,
        coloraxis="coloraxis",
        showscale=True,
    )
    fig = go.Figure(heatmap)
    fig.show()

as you can see, three cells are empty(where z-value equals to None) and thus, text is not shown.
What I want to achieve is just show text on such cells. Is it possible?

1 Like

Thanks for the MRE, @ilazariev . I’m talking to my colleagues to see if there is any way around displaying text when z values are None.

Hi @ilazariev
It looks like the text is there, it’s just white and very hard to see. Try to change the text color.
fig.update_traces(textfont_color='black').

Full code:

import plotly.graph_objects as go

z = [[None, None, 3], [3, 4, 3], [5, 6, None]]
text = [[1, 2, 3], [4, 5, 6], [7, 8, 9]]
heatmap = go.Heatmap(
    x=[0, 1, 2],
    y=[0, 1, 2],
    z=z,
    texttemplate="%{text}",
    text=text,
    coloraxis="coloraxis",
    showscale=True,
)
fig = go.Figure(heatmap)
fig.update_traces(textfont_color='black')
fig.show()

1 Like

thank you very much!