From b13cd4ca71148e58984c43853af8412129a6833a Mon Sep 17 00:00:00 2001 From: Michael Grund <23025878+michaelgrund@users.noreply.github.com> Date: Wed, 4 Aug 2021 17:19:21 +0200 Subject: [PATCH] Add gallery example for grdclip (#1396) Co-authored-by: Dongdong Tian --- examples/gallery/images/grdclip.py | 36 ++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 examples/gallery/images/grdclip.py diff --git a/examples/gallery/images/grdclip.py b/examples/gallery/images/grdclip.py new file mode 100644 index 00000000000..989ce26ce3f --- /dev/null +++ b/examples/gallery/images/grdclip.py @@ -0,0 +1,36 @@ +""" +Clipping grid values +-------------------- +The :meth:`pygmt.grdclip` method allows to clip defined ranges of grid values. +In the example shown below we set all elevation values (grid points) smaller +than 0 m (in general the bathymetric part of the grid) to a common value of +-2000 m via the ``below`` parameter. +""" + +import pygmt + +fig = pygmt.Figure() + +# Define region of interest around Iceland +region = [-28, -10, 62, 68] + +# Load sample grid (3 arc minute global relief) in target area +grid = pygmt.datasets.load_earth_relief(resolution="03m", region=region) + +# Plot original grid +fig.basemap(region=region, projection="M12c", frame=["f", '+t"original grid"']) +fig.grdimage(grid=grid, cmap="oleron") + +# Shift plot origin of the second map by "width of the first map + 0.5 cm" +# in x direction +fig.shift_origin(xshift="w+0.5c") + +# Set all grid points < 0 m to a value of -2000 m. +grid = pygmt.grdclip(grid, below=[0, -2000]) + +# Plot clipped grid +fig.basemap(region=region, projection="M12c", frame=["f", '+t"clipped grid"']) +fig.grdimage(grid=grid) +fig.colorbar(frame=["x+lElevation", "y+lm"], position="JMR+o0.5c/0c+w8c") + +fig.show()