Isolating a country with topographic data

First time working with map data, so pardon failures in terminology.

I looked through this forum/the internet and I couldn’t find this usage of GMT, through I’m sure it has been done. Sorry if this is a duplicate post…

I am trying to create a map consisting of just the country outline with elevation data inside. (ie Elevation data inside the Romania border, just transparent (or white) outside).

Below is my best attempt, but notice there is some extra land included near the bottom left. Also, I’d like this to be flexible for any country, so I don’t want to have to figure out which country codes to white-out with the dcw option every time I want to make one of these maps.

import pygmt
fig = pygmt.Figure()

# Load sample earth relief data
region = "RO+r1"
fig.basemap(region=region, projection="M3i", frame=True)

grid = pygmt.datasets.load_earth_relief(resolution="30s", region=region,)
fig = pygmt.Figure()
fig.grdimage(grid=grid, projection="M3i")


With pure gmt it is :

gmt begin test png
gmt coast -ERO+c -JM10c
gmt grdimage @earth_relief_01m
gmt coast -Q
gmt end show

I assume all the steps are the same in pygmt somehow.

  1. Use coast to clip the country you want
  2. Use grdimage to plot the topography (@earth_relief_XX)
  3. Quit the clip

So instead of plotting a rectangular region and white-out all countries, plot only region="RO"


Great! Just what I needed.