Heapmap displays wrong colors for np.ones matrix

I’m updating the values of a heatmap (programmatically setting as np.ones matrix):

heat_map = fig.data[0]
heat_map.colorscale = [[0.0, "rgb(255,50,10)"], [1.0, "rgb(255,255,255)"]]
heat_map.z = np.ones((root_count, int(nearest/root_count)), dtype=float)

Now I expect that the whole plot is white, but instead it seems it like its the color for 0.5 in the color scale.

It works if I set the first value/row to 0.0.

Is this a bug or am I doing something wrong? The heatmap is created inside a FigureWidget if that helps.

Thank you so much for your help!

Hi, in addition to the colorscale you also need here to give the bounds of your z range, The code below does what you want I think

import numpy as np
import plotly.graph_objects as go
x = np.ones((10, 10))
fig = go.Figure(data=go.Heatmap(z=x, zauto=False, zmin=0, zmax=1,
                                colorscale = [[0.0, "rgb(255,50,10)"], [1.0, "rgb(255,255,255)"]]))
fig.show()
1 Like

I now had the time to check your solution and it works! Thanks :slight_smile:

three reasons why you should buy plotly pro: support open source, get great support, host your plots and dashboards online