(53) Building subplots and using per-country shading — GMT 6.4.0 documentation

# (53) Building subplots and using per-country shading

This example illustrates two separate effects:

1. How to automate the plotting of a large set of subplot panels via a simple loop that picks up panel-specific parameters from a configuration file.

2. How to highlight a country using a DEM with darker ambient shading outside the country boundaries from DCW.

We use the 6 arc-minute global relief file for these plots and show topographic relief in an equal-area block of 3000 by 3000 km centered on one of the dozen most populated cities in the world. Apart from the metadata for each city, all subplot panels are identical, thus making a simple loop over the metadata preferable to writing 12 near-identical subplot sections. Note: For optimal resolution you should switch to the 2x2 arc-minute relief data instead.

We use a small table containing longitude, latitude, population (in millions), ISO-2 country code, and city name for the 12 cities; see https://simplemaps.com/data/world-cities for the full data set.

The example script then reads one line at the time from the metadata file and creates a DEM map for that city, embellished with a tag containing the city and the population, while using the ISO-2 country code to set up a clip path to highlight the relief inside its boundaries as given by the Digital Chart of the World (DCW). We use the city custom symbol to indicate the location of the city at the center of each map.

    #!/usr/bin/env bash
    # GMT_DISABLE_TEST
    #               GMT EXAMPLE 53
    #
    # Purpose:      Illustrate subplot with loops
    # GMT modules:  makecpt, subplot, set, plot, grdimage, clip, coast
    #

    gmt begin ex53
    	gmt set PROJ_ELLIPSOID Sphere MAP_ANNOT_OBLIQUE lon_horizontal,lat_parallel,tick_normal FONT_TAG 10p
    	gmt makecpt -Cterra
    	data=$(gmt which -G @Top12Cities.txt)
    	gmt subplot begin 4x3 -Fs6c -A+gwhite+p0.25p+o0.2c+sblack@50 -Baf -R-1500/1500/-1500/1500+uk -X1c -Y0.9c
    		while read lon lat population iso name; do
    			gmt subplot set -A"${name} [${population}M]"
    			gmt grdimage @earth_relief_06m -JA${lon}/${lat}/? -I+m-0.5
    			gmt coast -E${iso}+c
    			gmt grdimage @earth_relief_06m -JA${lon}/${lat}/? -I+d
    			gmt clip -C
    			gmt coast -E${iso}+pfaint -N1/thinner,darkred
    			echo ${lon} ${lat} | gmt plot -Skcity/0.25c -Gred -W0.5p -B0
    		done < $data
    	gmt subplot end
    	rm -f Top12Cities.txt
    gmt end show

Building subplots and using per-country shading.