More colorbar user errors (or bugs?)

In the process of finding a way to create the log-scale colorbar I needed, I ran into a few unexpected issues. I don’t know if these are user errors or bugs. The script to create the sample figure is listed below the figure, and the CPT and annotation files are linked at the bottom.

  1. Custom axes (-Bpxc) - lines separating colors aren’t plotted for custom annotations with afg, subplot a
    • I couldn’t find the -Bpxc option documented anywhere except Custom Axes, linked from a paragraph deep in the full -B docs.
  2. With a log-scale, -Q, the calculated dimensions of the colorbar seem to be off (based on the colorbar box), see subplots b and c.
  3. On a log-scale -Q colorbar, adding a unit label with -S+y doesn’t work, subplot c. The unit label is plotted with -By+l, but this strips off the annotations as in subplot d.

gmt begin sample_colorbar_issues png
  gmt subplot begin 4x1 -Fs5i/0.25i -A+JLM -R0/1/0/1
    gmt subplot set # a
    gmt colorbar -Cseis_pgv.cpt.txt -DjCM+h -F -Q -Bpxc"annots.txt" -By+l"cm/s"
    gmt subplot set # b
    gmt colorbar -Cseis_pgv.cpt.txt -DjCM+h -F -Q
    gmt subplot set # c
    gmt colorbar -Cseis_pgv.cpt.txt -DjCM+h -F -Q -S+y"cm/s"
    gmt subplot set # d
    gmt colorbar -Cseis_pgv.cpt.txt -DjCM+h -F -Q -By+l"cm/s"
  gmt subplot end
gmt end show
  • seis_pgv.cpt.txt (462 Bytes) - created by hand with color picker to replicate a colleagues color scale
  • annots.txt (117 Bytes) - created by hand, could be derived from CPT, e.g. awk '{print $1, "afg"} END{print $3, "afg"}' seis_pgv.cpt.txt > annots.txt
$ tail -n 5 annots.txt
70 f
80 afg
90 f
100 afg
200 afg


Thanks Jason, we will have a look. colormap uses -B so I do not think the documentation on custom axes is any more hidden there than, say, grdcontour. It is a relatively rarely used scheme, and your case is no exception I think. Have you tried --MAP_ANNOT_MIN_SPACING=18p (or whatever) with -Bpx3 to see if it will eliminate some of the dense annotations near 7,8,9?
The other cases smells like bugs to me.

1 Like

Hmm, I tried it with -Bpx3 --MAP_ANNOT_MIN_SPACING=18p (and larger) and it doesn’t seem to have an effect on the colorbar annotations (log or linear, as in subplot c). Did I misunderstand how this should work? I also tried setting the spacing to auto, with the same lack of effect. The command I used, within a subplot, is:

gmt colorbar -Cseis_pgv.cpt.txt -DJCM+h -Q -Bpx3 -Bx+l"label" --MAP_ANNOT_MIN_SPACING=36p
# the last subplot omits -Q, which may not be appropriate


Thanks for trying - I was not sure if it would work. I will see why not - seems like equally useful here as for map frames.

1 Like

Thanks for reporting this embarrassingly long list of issues! I believe all these bugs have now been fixed in master. The result we get now when running your example is shown below:

1 Like