Fix colorscale range

Hi!
I’ve got a problem. I need to fix min and max values for heatmap colorscale. I’ve tried to create a custom one, but plotly ignored CS array (array of ticks for colorbar), and established min value for color bar as min value in TWW array (2d array with intensity)

Q1=np.max(TWW)
Q2=np.min(TWW)
Q=np.max([np.abs(Q1),np.abs(Q2)])
nt=10
dQ=2.0*Q/nt
CS=dQ*np.arange(nt+1)-Q
print(CS)
print(n2,n1,m2,m1)
trace=go.Heatmap(x=xp[n1:n2], y=yp[m1:m2], z=np.transpose(TWW[n1:n2,m1:m2]),colorbar=dict(
        title="Twist",titleside="top",tickvals=CS))
data=[trace]
layout = go.Layout(scene = dict(
    xaxis=dict(nticks=20,range=[0, 1]),
    yaxis=dict(nticks=20,range=[0, 1])
    ))
fig=go.Figure(data=data,layout=layout)
1 Like

@vanis You can fix the z-values range to be colormapped, by setting zmin, zmax in go.Heatmap`. In the example I posted answering your question https://community.plotly.com/t/colorscale-text-size/30615/2,
after plotting the initial Figure, perform the following updates to compare the corresponding colorbars:

fig.data[0].update(zmin=0.2, zmax=0.8)

5 Likes

It works, many thanks!