Plot with broken (interrupted) axis

Following this feature request on GitHub

I created a broken axis map. Usually only the -Y or the -X axis needs an extension … but why not both ? And why only once ?

The idea is to :

  1. Use select to extract the points in each region
  2. Use mapproject to get the paper position of these points
  3. Add the desired offset
  4. Use mapproject -I to get the plot position in a “normalized” region
  5. Plot region 1
  6. Plot region 2 with offset
  7. Plot region “normalized” with reverse offset

So for 2 regions (broken axis on -X for example), we end up with 3 basemaps (n+1)

Anyway … here’s the Creature plot :

cat << 'EOF' > test.txt
1 2
4 7
5 1008
9 1003
102 8
106 3
109 7
1002 2
1004.5 5
1006 6
1008 1001
EOF

region_bl="-R0/10/0/10"
region_ml="-R0/10/100/110"
region_tl="-R0/10/1000/1010"

region_bc="-R100/110/0/10"
region_mc="-R100/110/100/110"
region_tc="-R100/110/1000/1010"

region_br="-R1000/1010/0/10"
region_mr="-R1000/1010/100/110"
region_tr="-R1000/1010/1000/1010"


figsz=5
dn=0.5

offset=$(gmt math -Q $figsz $dn ADD = )

projection="-JX${figsz}c"

gmt begin test png

    # Extract points within regions (repeat per region)
    gmt select $region_bl test.txt > pts_bl.txt 
    gmt select $region_tl test.txt > pts_tl.txt
    gmt select $region_bc test.txt > pts_bc.txt 
    gmt select $region_br test.txt > pts_br.txt
    gmt select $region_tr test.txt > pts_tr.txt

    # Project in unit paper
    gmt mapproject $region_bl $projection -Dc pts_bl.txt > pts_rep_bl.txt
    gmt mapproject $region_tl $projection -Dc pts_tl.txt > pts_rep_tl.txt
    gmt mapproject $region_bc $projection -Dc pts_bc.txt > pts_rep_bc.txt
    gmt mapproject $region_br $projection -Dc pts_br.txt > pts_rep_br.txt
    gmt mapproject $region_tr $projection -Dc pts_tr.txt > pts_rep_tr.txt 

    # Shift on paper
    gmt math pts_rep_tl.txt -C1     $offset 2 MUL ADD   = pts_rep_tl.txt 
    gmt math pts_rep_bc.txt -C0     $offset ADD         = pts_rep_bc.txt 
    gmt math pts_rep_br.txt -C0     $offset 2 MUL ADD   = pts_rep_br.txt
    gmt math pts_rep_tr.txt -C0,1   $offset 2 MUL ADD   = pts_rep_tr.txt

    cat $(ls -tr pts_rep_*) > test2.txt

    # inverse project in normalized space
    gmt mapproject -R0/1/0/1 -JX$(gmt math -Q $figsz 3 MUL $dn 2 MUL ADD =) -I test2.txt > test3.txt

    # Normalized plot
    gmt plot -R0/1/0/1 -JX$(gmt math -Q $figsz 3 MUL $dn 2 MUL ADD =) test3.txt -Wthicker,blue,-. -l"re-projected"

    # Bottom Left
    gmt basemap ${region_bl} ${projection} -Ba2f1g2 --MAP_FRAME_PEN=0p
    gmt basemap -Blb
        gmt plot test.txt -Sc0.25c -Gred -l"points in BL cadran"
        gmt plot test.txt -Wthicker,red -t30

    # Middle Left
    gmt basemap ${region_ml} -Bya2f1g2 -Bxg2 -Y${offset}c --MAP_FRAME_PEN=0p
    gmt basemap -Bl

    # Top Left
    gmt basemap ${region_tl} -Bya2f1g2 -Bxg2 -Y${offset}c --MAP_FRAME_PEN=0p
    gmt basemap -Btl
        gmt plot test.txt -Sc0.25c -Ggreen -l"points in TL cadran"
        gmt plot test.txt -Wthicker,green -t30

    # Bottom center
    gmt basemap ${region_bc} -Byg2 -Bxa2f1g2 -Y-$(gmt math -Q ${offset} 2 MUL =)c -X${offset} --MAP_FRAME_PEN=0p
    gmt basemap -Bb
        gmt plot test.txt -Sc0.25c -Gblack -l"points in BC cadran"
        gmt plot test.txt -Wthicker,black -t30

    # Middle center
    gmt basemap ${region_mc} -Bxg2 -Byg2 -Y${offset}c --MAP_FRAME_PEN=0p

    # Top center
    gmt basemap ${region_tc} -Bxg2 -Byg2 -Y${offset}c --MAP_FRAME_PEN=0p
    gmt basemap -Bt

    # Bottom right
    gmt basemap ${region_br} -Bxa2f1g2 -Byg2 -Y-$(gmt math -Q ${offset} 2 MUL =)c -X${offset} --MAP_FRAME_PEN=0p
    gmt basemap -Bbr
        gmt plot test.txt -Sc0.25c -Gyellow -l"points in BR cadran"
        gmt plot test.txt -Wthicker,yellow -t30

    # Middle right
    gmt basemap ${region_mr} -Bxg2 -Byg2 -Y${offset}c --MAP_FRAME_PEN=0p
    gmt basemap -Br

    # Top right
    gmt basemap ${region_tr} -Bxg2 -Byg2 -Y${offset}c --MAP_FRAME_PEN=0p
    gmt basemap -Brt
        gmt plot test.txt -Sc0.25c -Gmagenta -l"points in TR cadran"
        gmt plot test.txt -Wthicker,magenta

gmt end show

There’s certainly a way to automatize these steps, but for most of the cases, I think this is enough.