Colorbar with twin scales? [gmt.jl]

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:

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 

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

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.

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?

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)

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)

Thanks! Just what I was looking for.