Hello gmt users, I posted this question because I didn’t get the expected results while using gmt’s legend module. According to the legend module manual, the symbol’s fill can be specified by cpt and z=value format. However, in the case of categorical cpt, this method failed.
First, prepare the following categorical cpt.
#cpt_file.cpt
H red
He orange
Li yellow
Be green
B blue
C purple
And then create a legend file like this:
#legend_file
A cpt_file.cpt
S - c 0.3c z=H black - Hydrogen
S - c 0.3c z=He black - Helium
S - c 0.3c z=Li black - Lithium
S - c 0.3c z=Be black - Berylium
S - c 0.3c z=B black - Boron
S - c 0.3c z=C black - Carbon
If I run a simple script like this…
#!/bin/bash
gmt begin gmt_result png
gmt basemap -R0/1/0/1 -JX5c -B
gmt legend legend_file -DjRM+w3c+o0.1c -F+p
gmt end show
As shown in the figure above, only the first fill is correct, but all other fills come out the same as the first fill.
A regular cpt like this doesn’t cause any problems:
#cpt_file.cpt
1 red 2 orange
2 orange 3 yellow
3 yellow 4 green
4 green 5 blue
5 blue 6 purple
6 purple 7 purple
#legend_file
A cpt_file.cpt
S - c 0.3c z=1 black - One
S - c 0.3c z=2 black - Two
S - c 0.3c z=3 black - Three
S - c 0.3c z=4 black - Four
S - c 0.3c z=5 black - Five
S - c 0.3c z=6 black - Six
I’m wondering if this is really a bug, or if it’s explained in the manual but I couldn’t find it. My operating system is Ubuntu 22.04 LTS, gmt version is 6.3, and I installed it via apt.