Modify colorbar for range of value?


It might be easier to explain on a picture :

So the topography and bathymetry are given by @earth_relief and with the coast command I overlay a semi-transparent blue colour over the sea.

Now I’d like to also add this same hue to the colorbar, only for the negative values (bathymetry) … Is there a way to achieve that ?

Thanks !

gmt begin test png 
    gmt makecpt -Cgray -T-2500/2500 -H -I > relief.cpt
    gmt grdimage -R30/110/-30/30 -JM5c @earth_relief_03m -I+d -Crelief.cpt
    gmt coast -Dh -Wdefault,black -Sdeepskyblue -t25 -Bafg -B+t"A map" --MAP_GRID_PEN=thinner,gray
    gmt colorbar -Crelief.cpt -D+e -Bxaf+l"topography" -By+l"[m]"
gmt end show

no known solution ?

Maybe create 2 CPT and combined them into one??

Probably something like this (add -H if in modern mode):

gmt makecpt -Cdeepskyblue -T-5000/0 -N > my.cpt
gmt makecpt -Cgray -G0.5/1 -T0/2500 -N >> my.cpt

It’s a good alternative solution, but it doesn’t really do the trick… With this way I’m loosing the bathymetry in the colorbar (as well as some texture in the ocean).

OK, See what you want. Perhaps try gmt math RGB2HSV on the graycpt for the negative z values, then change the H (hue) to that of the deepskyblue color and convert back with HSV2RGB and assemble the two pieces.

I’m not too familiar with this. I tried to apply

makecpt -Cgray -T-2500/2500 -N -H > relief.cpt
gmt math relief.cpt 0 LE RGB2HSV = relief_hue.cpt

But the second line already fails.
I think I need to apply math to -C1-3 only, but then I loose the depth column. Also LE output only 0 and 1 so not very useful here.
The workaround would be to use 2 cpt like you suggested earlier, but the real problem stays the same : I can’t use RGB2HSV as the cpt contains value such as “gray10”.


I don’t have time to try this for you but you would probably need to use awk to just output r g b for gmt math to read since 255/45/45 is not going to work. See -Fr for numerical output instead of gray10 and white.

Thanks @pwessel. That could be interesting to learn how to use RGB2[…], but the application is definitely not worth the time. Would have been nice to have an easy workaround but I’ll just change the appearance.

this script might be helpful although its different from what you want but oceans topography colors are in colorbar

gmt begin test png 
    gmt grdimage -R30/110/-30/30 -JM5i @earth_relief_03m -I+d -Cglobe
    gmt coast -Dh -Wdefault,black -Sdeepskyblue -t25 -Bafg -B+t"A map" --MAP_GRID_PEN=thinner,gray
    gmt colorbar -Dx6.2c/-1.19c+w10c/0.3c+jBC+h -Bxaf+l"topography" -By+l"[m]"
gmt end show

Hum, nice indeed. I’ve never realized colorbar could handle two information this way.