Hi all,
A query, how can I do to center the color bar labels? I tried with the -L0.1 option but it did not work. Also, how could I remove the horizontal lines from the labels?
This is my code:
#!/usr/bin/bash
region=-81/-80/-4/-3.3
gmt begin test_colorbar
gmt set MAP_TICK_LENGTH_PRIMARY 0
gmt set MAP_TICK_LENGTH_SECONDARY 0
cat > test.cpt <<END
# Color Table
# COLOR_MODEL = RGB
-1484.68054199 37 57 175 -1370.67816772 40 127 251 ;10th class
-1370.67816772 40 127 251 -1256.67579345 50 190 255 ;9th class
-1256.67579345 50 190 255 -1142.67341918 106 235 255 ;8th class
-1142.67341918 106 235 255 -1028.67104491 138 236 174 ;7th class
-1028.67104491 138 236 174 -914.66867064 205 255 162 ;6th class
-914.66867064 205 255 162 -800.66629637 240 236 121 ;5th class
-800.66629637 240 236 121 -686.66392210 255 189 87 ;4th class
-686.66392210 255 189 87 -572.66154783 255 161 68 ;3rd class
-572.66154783 255 161 68 -458.65917356 255 186 133 ;2nd class
-458.65917356 255 186 133 -344.656799316 255 255 255 ;1st class
B black
F white
END
gmt colorbar -Ctest.cpt -R$region -DJMR+w5.0c/0.5c+o1.0c/-2.0c -L0.1 -V
gmt end show
And I get this figure:
test_colorbar.pdf (5.9 KB)
I am using GMT 6.6.0_4a8f608_2025.02.01.
Thank you very much in advance for your help.
Best wishes,
Oscar
And you also want to use discrete CPTs for categorical displays.
Thank you Joaquim for your help. Yes, I used that script as a reference, but I had no luck. I was able to fix it with makecpt and the -F+c option.
#!/usr/bin/bash
region=-81/-80/-4/-3.3
gmt begin test_colorbar
cat > test.cpt <<END
# Color Table
# COLOR_MODEL = RGB
-1484.68054199 37 57 175 -1370.67816772 40 127 251 ;10th class
-1370.67816772 40 127 251 -1256.67579345 50 190 255 ;9th class
-1256.67579345 50 190 255 -1142.67341918 106 235 255 ;8th class
-1142.67341918 106 235 255 -1028.67104491 138 236 174 ;7th class
-1028.67104491 138 236 174 -914.66867064 205 255 162 ;6th class
-914.66867064 205 255 162 -800.66629637 240 236 121 ;5th class
-800.66629637 240 236 121 -686.66392210 255 189 87 ;4th class
-686.66392210 255 189 87 -572.66154783 255 161 68 ;3rd class
-572.66154783 255 161 68 -458.65917356 255 186 133 ;2nd class
-458.65917356 255 186 133 -344.656799316 255 255 255 ;1st class
B black
F white
END
gmt makecpt -H -Ctest.cpt -F+c"10th class,9th class,8th class,7th class,6th class,5th class,4th class,3rd class,2nd class,1st class" > test_final.cpt -V
gmt colorbar -Ctest_final.cpt -R$region -DJMR+w5.0c/0.5c+o1.0c/-2.0c -L0.1c -V
gmt end show
I had as a result:
test_colorbar.pdf (5.8 KB)
Cheers,
Oscar
Yes, categorical CPTs have their own mood. But for me (suffered with them once), now I just do like:
julia> C = makecpt(cmap=:categorical, range="Neogene,Paleogene,Cretaceous,Jurassic,Triassic,Permian,Carboniferous,Devonian,Silurian,Ordovician,Cambrian,Precambrian")
Extract of a GMTcpt exposed as a GMTdataset for display.
CATEGORICAL palette.
Model: rgb
Color depth: 24
12×5 GMTdataset{Float64, 2}
Row │ z r g b alpha Labels
─────┼─────────────────────────────────────────────────
1 │ 1.0 0.0 255.0 0.0 0.0 Neogene
2 │ 2.0 0.0 0.0 255.0 0.0 Paleogene
3 │ 3.0 255.0 0.0 0.0 0.0 Cretaceous
4 │ 4.0 0.0 255.0 255.0 0.0 Jurassic
5 │ 5.0 255.0 153.0 238.0 0.0 Triassic
6 │ 6.0 255.0 221.0 102.0 0.0 Permian
7 │ 7.0 0.0 102.0 0.0 0.0 Carboniferous
8 │ 8.0 0.0 0.0 102.0 0.0 Devonian
9 │ 9.0 170.0 85.0 68.0 0.0 Silurian
10 │ 10.0 0.0 136.0 204.0 0.0 Ordovician
11 │ 11.0 255.0 17.0 255.0 0.0 Cambrian
12 │ 12.0 255.0 238.0 238.0 0.0 Precambrian
julia> viz(C)
1 Like