Getting color value from CPT + z-value

Waking up an old post.

In August 2024, I found that I needed to extend Pål’s nifty suggestion in order to make it work correctly. I used something like this (to sample from a color bar with min= -6, to max +6, at the value -1.24):

gmt makecpt -T-6/6/0.5 -Cpolar -Fr -N | tr '/' '\t' | gmt sample1d -i0:3 -T-1.24, -o1-3 | tr '\t' '/'

Here’s the output: 202.3/202.3/255

The -N in makecpt omits the background, foreground and NaN color fields. The tr is the translate characters function, to convert from slashed fields to tab fields, then back again.

1 Like