forked from GenericMappingTools/pygmt
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add gallery example for grdlandmask (GenericMappingTools#1469)
Co-authored-by: Dongdong Tian <[email protected]>
- Loading branch information
1 parent
d24da86
commit fbdacf9
Showing
1 changed file
with
34 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
""" | ||
Create 'wet-dry' mask grid | ||
-------------------------- | ||
The :meth:`pygmt.grdlandmask` method allows setting | ||
all nodes on land or water to a specified value using | ||
the ``maskvalues`` parameter. | ||
""" | ||
|
||
import pygmt | ||
|
||
fig = pygmt.Figure() | ||
|
||
# Define region of interest | ||
region = [-65, -40, -40, -20] | ||
|
||
# Assign a value of 0 for all water masses and a value of 1 for all land masses. | ||
# Use shoreline data with (l)ow resolution and set the grid spacing to | ||
# 5 arc minute in x and y direction. | ||
grid = pygmt.grdlandmask(region=region, spacing="5m", maskvalues=[0, 1], resolution="l") | ||
|
||
# Plot clipped grid | ||
fig.basemap(region=region, projection="M12c", frame=True) | ||
|
||
# Define a colormap to be used for two categories, define the range of the | ||
# new discrete CPT using series=(lowest_value, highest_value, interval), | ||
# use color_model="+cwater,land" to write the discrete color palette | ||
# "batlow" in categorical format and add water/land as annotations for the | ||
# colorbar. | ||
pygmt.makecpt(cmap="batlow", series=(0, 1, 1), color_model="+cwater,land") | ||
|
||
fig.grdimage(grid=grid, cmap=True) | ||
fig.colorbar(position="JMR+o0.5c/0c+w8c") | ||
|
||
fig.show() |