# Colorbar with twin scales? \[gmt.jl\]

**URL:** <https://forum.generic-mapping-tools.org/t/colorbar-with-twin-scales-gmt-jl/1849>\
**Category:** GMT.jl Q&A\
**Created:** [June 30, 2021, 8:51pm UTC](https://forum.generic-mapping-tools.org/t/colorbar-with-twin-scales-gmt-jl/1849 "2021-06-30T20:51:03Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![tclements](https://yyz1.discourse-cdn.com/flex047/user_avatar/forum.generic-mapping-tools.org/tclements/32/1397_2.png) [@tclements](https://forum.generic-mapping-tools.org/u/tclements)\
**Post date:** [June 30, 2021, 8:51pm UTC](https://forum.generic-mapping-tools.org/t/colorbar-with-twin-scales-gmt-jl/1849/1 "2021-06-30T20:51:03Z")

</div>

Hello,

I would like to make a vertical colorbar with two different scales - one scale on the left and one on the right. Here is a MWE for what I’m trying to do:

```auto
using GMT 
G = GMT.peaks(); # varies from -8:6
# create scatter points with z values -1:1
x = (rand(400) .- 0.5) .* 6
y = (rand(400) .- 0.5) .* 6
z = (rand(400) .- 0.5) .* 2

C1 = GMT.makecpt(T=(-8,8,8 / 21), cmap=:vik); # -8:8
C2 = GMT.makecpt(T=(-1,1,1 / 21), cmap=:vik); # -1:1

grdimage(G ./ 8,C=C2)
scatter!(x,y,zcolor=z,C=C2)
colorbar!(C=C2,frame=(annot=:auto, ticks=:auto, xlabel="C2"),show=true) # this has C2 on the right 

```

 ![image](https://canada1.discourse-cdn.com/flex047/uploads/gmt/original/2X/9/9629913051272d3390b4078c853b9cfae78f2c79.png)

Is there a way to show the values for the `C1` colormap on the left side of the colorbar? Thanks!

---

<div class="post-metadata">

**Author:** ![Joaquim](https://yyz1.discourse-cdn.com/flex047/user_avatar/forum.generic-mapping-tools.org/joaquim/32/16_2.png) [@Joaquim](https://forum.generic-mapping-tools.org/u/Joaquim)\
**Post date:** [June 30, 2021, 11:23pm UTC](https://forum.generic-mapping-tools.org/t/colorbar-with-twin-scales-gmt-jl/1849/2 "2021-06-30T23:23:46Z")

</div>

That’s simpler that it seems (but with a but).  
Just add another call to `colorbar` and put it on the left side (and move the `show` to last one), _e.g._

```auto
colorbar!(C=C2,frame=(annot=:auto, ticks=:auto, xlabel="C2"));
colorbar!(C=C1, frame=(annot=:auto, ticks=:auto, xlabel="C1"), pos=(anchor=:ML, offset=0.7), show=1)

```

but I confess that I don’t understand why the second bar is not centered at the same horizontal position @pwessel?

 ![GMTjl_tmp](https://canada1.discourse-cdn.com/flex047/uploads/gmt/original/2X/8/8d0f66524dc63d2f0c217ec3a2d4bbd2a9d7321b.png)

---

<div class="post-metadata">

**Author:** ![Joaquim](https://yyz1.discourse-cdn.com/flex047/user_avatar/forum.generic-mapping-tools.org/joaquim/32/16_2.png) [@Joaquim](https://forum.generic-mapping-tools.org/u/Joaquim)\
**Post date:** [June 30, 2021, 11:52pm UTC](https://forum.generic-mapping-tools.org/t/colorbar-with-twin-scales-gmt-jl/1849/3 "2021-06-30T23:52:16Z")

</div>

Ghrrr, I found my error (not obvious). Because of the left annotations I was forced to add an offset. But the offset is `dx/dy` and if we omit `dy` it is set equal to `dx`. Hence the diagonal offset. Make it `offset=(0.7,0)`

```auto
colorbar!(C=C1, frame=(annot=:auto, ticks=:auto, xlabel="C1"), pos=(anchor=:ML, offset=(0.7,0)), show=1)

```

and one gets.  
(Note: my `vik` colors are different from yours but that’s probably because we updated those scientific colormaps and you are using an older GMT version)

 ![GMTjl_tmp](https://canada1.discourse-cdn.com/flex047/uploads/gmt/original/2X/0/0a27e32648cf428f9246ecfa674a16017d10dc2c.png)

---

<div class="post-metadata">

**Author:** ![tclements](https://yyz1.discourse-cdn.com/flex047/user_avatar/forum.generic-mapping-tools.org/tclements/32/1397_2.png) [@tclements](https://forum.generic-mapping-tools.org/u/tclements)\
**Post date:** [July 1, 2021, 12:10am UTC](https://forum.generic-mapping-tools.org/t/colorbar-with-twin-scales-gmt-jl/1849/4 "2021-07-01T00:10:55Z")

</div>

Thanks! Just what I was looking for.
