# Plotting heatmap PlotlyJS, double bar

**URL:** <https://discourse.julialang.org/t/plotting-heatmap-plotlyjs-double-bar/80199>\
**Category:** Visualization\
**Tags:** plotlyjs\
**Created:** [April 28, 2022, 10:16am UTC](https://discourse.julialang.org/t/plotting-heatmap-plotlyjs-double-bar/80199 "2022-04-28T10:16:57Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Line](https://avatars.discourse-cdn.com/v4/letter/l/b38774/32.png) [@Line](https://discourse.julialang.org/u/Line)\
**Post date:** [April 28, 2022, 10:16am UTC](https://discourse.julialang.org/t/plotting-heatmap-plotlyjs-double-bar/80199/1 "2022-04-28T10:16:57Z")

</div>

Hi, I am plotting heatmap subplots using PlotlyJS package and get the problem of the bar being double. The input into the heatmap is just values of either 1, 2 or 3. I assume a part of the problem is some plots only take in two of these and that’s why the top of the bar is both 2 and 3. Does any one know how to fix this problem?  
 ![plot from model](https://global.discourse-cdn.com/julialang/original/3X/8/7/873f44c1b10e34d9fe4936f1fae2fcb8cb6109ca.png)

---

<div class="post-metadata">

**Author:** ![Line](https://avatars.discourse-cdn.com/v4/letter/l/b38774/32.png) [@Line](https://discourse.julialang.org/u/Line)\
**Post date:** [April 28, 2022, 10:29am UTC](https://discourse.julialang.org/t/plotting-heatmap-plotlyjs-double-bar/80199/2 "2022-04-28T10:29:59Z")

</div>

I feel like the answer could be in here in the part about ticktext/tickvals, but not able to understand it: [Heatmap traces in Julia](https://plotly.com/julia/reference/heatmap/#heatmap-legendgrouptitle-font)

---

<div class="post-metadata">

**Author:** ![empet](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/empet/32/221303_2.png) [@empet](https://discourse.julialang.org/u/empet)\
**Post date:** [April 28, 2022, 6:43pm UTC](https://discourse.julialang.org/t/plotting-heatmap-plotlyjs-double-bar/80199/3 "2022-04-28T18:43:26Z")

</div>

Your subplot of heatmaps seems to be defined in order to compare Decision rule at different times.  
A definition of subplots like this one, associates colorbar tickvals for each heatmap:

```julia
using PlotlyJS

fig1 = make_subplots(rows=1, cols=2)
add_trace!(fig1, heatmap(x=1:5, y=1:4, z=rand(2:7, 4,5)), row=1, col=1)
add_trace!(fig1, heatmap(x=1:4, y=1:4, z=rand(4:10, 4,4)), row=1, col=2)
relayout!(fig1, width=700, height=350)
display(fig1)

```

but if you are referencing each heatmap to the same coloraxis, i.e. a unique colorbar with zmin=min(of the values in the union of z-values of both heatmaps),  
and zmax=max (the same values as for zmin), then you also get unique tickvals for the colorbar:

```julia
fig2 = make_subplots(rows=1, cols=2)
add_trace!(fig2, heatmap(x=1:5, y=1:4, z=rand(2:7, 4,5), coloraxis="coloraxis"), row=1, col=1)
add_trace!(fig2, heatmap(x=1:4, y=1:4, z=rand(4:10, 4,4), coloraxis="coloraxis"), row=1, col=2)
relayout!(fig2, width=700, height=350)
display(fig2)

```

 ![subpl-heatmaps](https://global.discourse-cdn.com/julialang/original/3X/9/1/911bef654c208377ca583386602b4afe04543401.png)

---

<div class="post-metadata">

**Author:** ![Line](https://avatars.discourse-cdn.com/v4/letter/l/b38774/32.png) [@Line](https://discourse.julialang.org/u/Line)\
**Post date:** [April 29, 2022, 3:09pm UTC](https://discourse.julialang.org/t/plotting-heatmap-plotlyjs-double-bar/80199/4 "2022-04-29T15:09:23Z")

</div>

Thanks! This helped adding values for z in there. Now I did like this for every subplot and the bar is fine:

```julia
data = decision_rule[:, :, 5, 1, timestep]
    add_trace!(p, heatmap(z=data, y=0:1:20, x=0:1:20, zmin=1, zmax=3), row=1, col=1)

```
