Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Colorbar annotations plotting incorrectly when used in an inset plot. #8690

Open
ESaltPi opened this issue Feb 14, 2025 · 4 comments
Open

Colorbar annotations plotting incorrectly when used in an inset plot. #8690

ESaltPi opened this issue Feb 14, 2025 · 4 comments
Labels
bug Something isn't working

Comments

@ESaltPi
Copy link

ESaltPi commented Feb 14, 2025

Description of the problem
The tick marks are not aligning to the correct place on the color scale and thus there is some text that is well off the scale. You will see that I have plotted three insets below the main figure. The colorbar is part of the middle inset, yet the 2000 annotation plots near the right inset. Based on the cpt which i set to go from 5000 to 2000, the 1000’s should be placed on the actual bar. A solution does exist to fix the problem, but I believe that this is still a bug.

Full script that generated the error

#!/bin/bash

gmt begin Gofar625_79_inset_TEST ps,pdf,png E720 -C

gmt gmtset PROJ_LENGTH_UNIT inch
gmt gmtset PS_MEDIA archA
gmt gmtset FONT_ANNOT_PRIMARY 8,Helvetica,black
gmt gmtset FONT_ANNOT_SECONDARY 8,Helvetica,black
gmt gmtset FONT_LABEL 8,Helvetica,black
gmt gmtset FONT_TITLE 10,Helvetica,black
gmt gmtset PS_PAGE_ORIENTATION LANDSCAPE
gmt gmtset COLOR_BACKGROUND black
gmt gmtset COLOR_FOREGROUND white
gmt gmtset COLOR_NAN white

gmt gmtset FORMAT_GEO_MAP ddd.x
gmt gmtset MAP_FRAME_WIDTH 3p
gmt gmtset MAP_ANNOT_OFFSET_PRIMARY 5p

gmt basemap -Bpxa.02f.01 -Bpya.01 -R104.9745W/104.825W/4.575S/4.529S -JM10.5i -BNSWE+t"Preliminary Bathymetry with Earthquakes" \
            -LjRT+o0.2+w2k+f+l"Scale (km)" --MAP_TICK_LENGTH=0p --MAP_ANNOT_OBLIQUE=lat_parallel -Xc -Y3.25i

gmt inset begin -R-123.5/-30/-61/31r -JS-100/0/2i -DJLB+o-2.05i/0.4i -F+gwhite+p0.5p,black
gmt basemap -R-123.5/-30/-61/31r -JS-100/0/2i -Bxa10f5 -Bya10f5 \
        --MAP_FRAME_TYPE=inside --MAP_FRAME_AXES=eslt
gmt basemap -R-123.5/-30/-61/31r -JS-100/0/2i -Bxa30 -Bya30 \
        --MAP_FRAME_TYPE=inside -BSE --FORMAT_GEO_MAP=DDDG --FONT_ANNOT_PRIMARY=4,Helvetica,black
gmt inset end

gmt inset begin -R106.5W/102.0W/5.25S/3.25S -JM5i -DJRB+o-5.05i/0.4i -F+gwhite+p0.5p,black
gmt basemap -Bpxa1f0.5 -Bpya0.5f0.5 -LjLT+o0.2+w100k+l"Scale (km)" -BSEnw \
            --MAP_FRAME_TYPE=inside --MAP_FRAME_AXES=eslt --FORMAT_GEO_MAP=ddd.x
gmt inset end

gmt inset begin -R105.2W/104.6W/4.75S/4.4S -JM3i -DJLB+o-5.25i/0.4i -F+gwhite+p0.5p,black -N
gmt makecpt -Chaxby -T-5000/-2000 -H > haxby.cpt
gmt basemap -Bpxa0.2 -Bpya0.1 -LjLT+o0.2+w10k+l"Scale (km)" -BSEnw \
            --MAP_FRAME_TYPE=inside --MAP_FRAME_AXES=eslt --FORMAT_GEO_MAP=ddd.x
gmt colorbar -Chaxby.cpt -DJCB+w2.6i/0.1i+o0.0i/0.25i+h+ml -Bxa1000f250+l"Bathymetry Depth" -By+lm
rm -f haxby.cpt
gmt inset end

gmt end show

Actual outcome

Gofar625_79_inset_TEST.pdf

Expected outcome

The annotations on the bottom of the colorbar attached to the middle inset do not plot in the correct locations. A solution does exist to fix this bug: add your -R and -J parameters into the colorbar function.

System information

  • Operating system: Linux 22.04
  • GMT version (gmt --version): 6.5.0
@ESaltPi ESaltPi added the bug Something isn't working label Feb 14, 2025
Copy link

welcome bot commented Feb 14, 2025

👋 Thanks for opening your first issue here! Please make sure you filled out the template with as much detail as possible. We appreciate that you took the time to contribute!

Please make sure you read our Contributing Guide and abide by our Code of Conduct.

@joa-quim
Copy link
Member

Can you make this into a small example, just one or two lines?
I won't debug such a long script.

@ESaltPi
Copy link
Author

ESaltPi commented Feb 14, 2025

This script still produces the same error message which only appears once colorbar is initiated. I dont think I can shrink the script any further. Interestingly, if the basemap inside the inset is removed, it also fixes the colorbar.

Script:

#!/bin/bash

gmt begin Gofar625_79b_inset_TEST ps,pdf,png E720 -C

gmt basemap -Bpxa.02f.01 -Bpya.01 -R104.9745W/104.825W/4.575S/4.529S -JM6i -BNSWE -Xc -Y3.25i

gmt inset begin -R105.2W/104.6W/4.75S/4.4S -JM3i -DJLB+o-5.25i/0.4i -F+gwhite+p0.5p,black -N
gmt makecpt -Chaxby -T-5000/-2000 -H > haxby.cpt
gmt basemap -Bpxa0.2 -Bpya0.1 -BSEnw --MAP_FRAME_TYPE=inside
gmt colorbar -Chaxby.cpt -DJCB+w2.6i/0.1i+o0.0i/0.25i+h+ml -Bxa1000f250+l"Bathymetry Depth" -By+lm -Vd
gmt inset end

gmt end show

Image

@joa-quim
Copy link
Member

Thanks. I edited your post to remove the error message, that are no error at all. They are debug messages and being quite long make this unnecessarily long.

Also adding the find by @mkononets

https://forum.generic-mapping-tools.org/t/colorbar-annotation-placements/5732/2

that repeating the -R -J works around this issue

gmt colorbar -R105.2W/104.6W/4.75S/4.4S -JM3i -Chaxby.cpt -DJCB+w2.6i/0.1i+o0.0i/0.25i+h+ml -Bxa1000f250+l"Bathymetry Depth" -By+lm

which makes this issue ... almost solved (we are really short on manpower to address less priority issues)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants