# Fix colorscale range

**URL:** <https://community.plotly.com/t/fix-colorscale-range/30613>\
**Category:** 📊 Plotly Python\
**Created:** [October 29, 2019, 4:17pm UTC](https://community.plotly.com/t/fix-colorscale-range/30613 "2019-10-29T16:17:52Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![vanis](https://avatars.discourse-cdn.com/v4/letter/v/b19c9b/32.png) [@vanis](https://community.plotly.com/u/vanis)\
**Post date:** [October 29, 2019, 4:17pm UTC](https://community.plotly.com/t/fix-colorscale-range/30613/1 "2019-10-29T16:17:52Z")

</div>

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)
```

---

<div class="post-metadata">

**Author:** ![empet](https://avatars.discourse-cdn.com/v4/letter/e/977dab/32.png) [@empet](https://community.plotly.com/u/empet)\
**Post date:** [October 29, 2019, 5:10pm UTC](https://community.plotly.com/t/fix-colorscale-range/30613/2 "2019-10-29T17:10:15Z")

</div>

@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](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)`

---

<div class="post-metadata">

**Author:** ![vanis](https://avatars.discourse-cdn.com/v4/letter/v/b19c9b/32.png) [@vanis](https://community.plotly.com/u/vanis)\
**Post date:** [October 29, 2019, 5:45pm UTC](https://community.plotly.com/t/fix-colorscale-range/30613/3 "2019-10-29T17:45:30Z")

</div>

> [@empet](#):
>
> zmin=0.2

It works, many thanks!
