Skip to content

Commit b13cd4c

Browse files
Add gallery example for grdclip (#1396)
Co-authored-by: Dongdong Tian <[email protected]>
1 parent bb618b7 commit b13cd4c

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

examples/gallery/images/grdclip.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
"""
2+
Clipping grid values
3+
--------------------
4+
The :meth:`pygmt.grdclip` method allows to clip defined ranges of grid values.
5+
In the example shown below we set all elevation values (grid points) smaller
6+
than 0 m (in general the bathymetric part of the grid) to a common value of
7+
-2000 m via the ``below`` parameter.
8+
"""
9+
10+
import pygmt
11+
12+
fig = pygmt.Figure()
13+
14+
# Define region of interest around Iceland
15+
region = [-28, -10, 62, 68]
16+
17+
# Load sample grid (3 arc minute global relief) in target area
18+
grid = pygmt.datasets.load_earth_relief(resolution="03m", region=region)
19+
20+
# Plot original grid
21+
fig.basemap(region=region, projection="M12c", frame=["f", '+t"original grid"'])
22+
fig.grdimage(grid=grid, cmap="oleron")
23+
24+
# Shift plot origin of the second map by "width of the first map + 0.5 cm"
25+
# in x direction
26+
fig.shift_origin(xshift="w+0.5c")
27+
28+
# Set all grid points < 0 m to a value of -2000 m.
29+
grid = pygmt.grdclip(grid, below=[0, -2000])
30+
31+
# Plot clipped grid
32+
fig.basemap(region=region, projection="M12c", frame=["f", '+t"clipped grid"'])
33+
fig.grdimage(grid=grid)
34+
fig.colorbar(frame=["x+lElevation", "y+lm"], position="JMR+o0.5c/0c+w8c")
35+
36+
fig.show()

0 commit comments

Comments
 (0)