Skip to content

Commit 3a5e8db

Browse files
Tutorial and Intro for Figure.grdcontour: Adjust line length and parameter order (#3212)
1 parent 48f12cc commit 3a5e8db

File tree

2 files changed

+74
-103
lines changed

2 files changed

+74
-103
lines changed

examples/get_started/02_contour_map.py

Lines changed: 51 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,10 @@
22
2. Create a contour map
33
=======================
44
5-
This tutorial page covers the basics of creating a figure of the Earth
6-
relief, using a remote dataset hosted by GMT, using the method
7-
:meth:`pygmt.datasets.load_earth_relief`. It will use the
8-
:meth:`pygmt.Figure.grdimage`, :meth:`pygmt.Figure.grdcontour`,
9-
:meth:`pygmt.Figure.colorbar`, and :meth:`pygmt.Figure.coast` methods for
10-
plotting.
5+
This tutorial page covers the basics of creating a figure of the Earth relief, using a
6+
remote dataset hosted by GMT, using the method :meth:`pygmt.datasets.load_earth_relief`.
7+
It will use the :meth:`pygmt.Figure.grdimage`, :meth:`pygmt.Figure.grdcontour`,
8+
:meth:`pygmt.Figure.colorbar`, and :meth:`pygmt.Figure.coast` methods for plotting.
119
"""
1210

1311
# %%
@@ -17,13 +15,12 @@
1715
# Loading the Earth relief dataset
1816
# --------------------------------
1917
#
20-
# The first step is to use :meth:`pygmt.datasets.load_earth_relief`.
21-
# The ``resolution`` parameter sets the resolution of the remote grid file,
22-
# which will affect the resolution of the plot made later in the tutorial.
23-
# The ``registration`` parameter determines the grid registration.
18+
# The first step is to use :meth:`pygmt.datasets.load_earth_relief`. The ``resolution``
19+
# parameter sets the resolution of the remote grid file, which will affect the
20+
# resolution of the plot made later in the tutorial. The ``registration`` parameter
21+
# determines the grid registration.
2422
#
25-
# This grid region covers the islands of Guam and Rota in the western Pacific
26-
# Ocean.
23+
# This grid region covers the islands of Guam and Rota in the western Pacific Ocean.
2724

2825
grid = pygmt.datasets.load_earth_relief(
2926
resolution="30s", region=[144.5, 145.5, 13, 14.5], registration="gridline"
@@ -34,18 +31,16 @@
3431
# Plotting Earth relief
3532
# ---------------------
3633
#
37-
# To plot Earth relief data, the method :meth:`pygmt.Figure.grdimage` can be
38-
# used to plot a color-coded figure to display the topography and bathymetry
39-
# in the grid file. The ``grid`` parameter accepts the input grid, which in
40-
# this case is the remote file downloaded in the previous step. If the
41-
# ``region`` parameter is not set, the region boundaries of the input grid are
42-
# used.
34+
# To plot Earth relief data, the method :meth:`pygmt.Figure.grdimage` can be used to
35+
# plot a color-coded figure to display the topography and bathymetry in the grid file.
36+
# The ``grid`` parameter accepts the input grid, which in this case is the remote file
37+
# downloaded in the previous step. If the ``region`` parameter is not set, the region
38+
# boundaries of the input grid are used.
4339
#
44-
# The ``cmap`` parameter sets the color palette table (CPT) used for portraying
45-
# the Earth relief. The :meth:`pygmt.Figure.grdimage` method uses the input
46-
# grid to relate the Earth relief values to a specific color within the CPT.
47-
# In this case, the CPT "oleron" is used; a full list of CPTs can be found
48-
# at :gmt-docs:`reference/cpts.html`.
40+
# The ``cmap`` parameter sets the color palette table (CPT) used for portraying the
41+
# Earth relief. The :meth:`pygmt.Figure.grdimage` method uses the input grid to relate
42+
# the Earth relief values to a specific color within the CPT. In this case, the CPT
43+
# "oleron" is used; a full list of CPTs can be found at :gmt-docs:`reference/cpts.html`.
4944

5045
fig = pygmt.Figure()
5146
fig.grdimage(grid=grid, frame="a", projection="M10c", cmap="oleron")
@@ -56,17 +51,17 @@
5651
# Adding a colorbar
5752
# -----------------
5853
#
59-
# To show how the plotted colors relate to the Earth relief, a colorbar can be
60-
# added using the :meth:`pygmt.Figure.colorbar` method.
54+
# To show how the plotted colors relate to the Earth relief, a colorbar can be added
55+
# using the :meth:`pygmt.Figure.colorbar` method.
6156
#
62-
# To control the annotation and labels on the colorbar, a list is passed to
63-
# the ``frame`` parameter. The value beginning with ``"a"`` sets the interval
64-
# for the annotation on the colorbar, in this case every 1,000 meters. To set
65-
# the label for an axis on the colorbar, the argument begins with either
66-
# ``"x+l"`` (x-axis) or ``"y+l"`` (y-axis), followed by the intended label.
57+
# To control the annotation and labels on the colorbar, a list is passed to the
58+
# ``frame`` parameter. The value beginning with ``"a"`` sets the interval for the
59+
# annotation on the colorbar, in this case every 1,000 meters. To set the label for an
60+
# axis on the colorbar, the argument begins with either ``"x+l"`` (x-axis) or ``"y+l"``
61+
# (y-axis), followed by the intended label.
6762
#
68-
# By default, the CPT for the colorbar is the same as the one set
69-
# in :meth:`pygmt.Figure.grdimage`.
63+
# By default, the CPT for the colorbar is the same as the one set in
64+
# :meth:`pygmt.Figure.grdimage`.
7065

7166
fig = pygmt.Figure()
7267
fig.grdimage(grid=grid, frame="a", projection="M10c", cmap="oleron")
@@ -78,18 +73,16 @@
7873
# Adding contour lines
7974
# --------------------
8075
#
81-
# To add contour lines to the color-coded figure, the
82-
# :meth:`pygmt.Figure.grdcontour` method is used. The ``frame`` and
83-
# ``projection`` are already set using :meth:`pygmt.Figure.grdimage` and are
84-
# not needed again. However, the same input for ``grid`` (in this case, the
85-
# variable named "grid") must be input again. The ``levels`` parameter sets
86-
# the spacing between adjacent contour lines (in this case, 500 meters). The
87-
# ``annotation`` parameter annotates the contour lines corresponding to the
88-
# given interval (in this case, 1,000 meters) with the related values, here
89-
# elevation or bathymetry. By default, these contour lines are drawn thicker.
90-
# Optionally, the appearance (thickness, color, style) of the annotated and
91-
# the not-annotated contour lines can be adjusted (separately) by specifying
92-
# the desired ``pen``.
76+
# To add contour lines to the color-coded figure, the :meth:`pygmt.Figure.grdcontour`
77+
# method is used. The ``frame`` and ``projection`` are already set using
78+
# :meth:`pygmt.Figure.grdimage` and are not needed again. However, the same input for
79+
# ``grid`` (in this case, the variable named "grid") must be input again. The ``levels``
80+
# parameter sets the spacing between adjacent contour lines (in this case, 500 meters).
81+
# The ``annotation`` parameter annotates the contour lines corresponding to the given
82+
# interval (in this case, 1,000 meters) with the related values, here elevation or
83+
# bathymetry. By default, these contour lines are drawn thicker. Optionally, the
84+
# appearance (thickness, color, style) of the annotated and the not-annotated contour
85+
# lines can be adjusted (separately) by specifying the desired ``pen``.
9386

9487
fig = pygmt.Figure()
9588
fig.grdimage(grid=grid, frame="a", projection="M10c", cmap="oleron")
@@ -102,10 +95,9 @@
10295
# Color in land
10396
# -------------
10497
#
105-
# To make it clear where the islands are located, the
106-
# :meth:`pygmt.Figure.coast` method can be used to color in the landmasses.
107-
# The ``land`` is colored in as "lightgray", and the ``shorelines`` parameter
108-
# draws a border around the islands.
98+
# To make it clear where the islands are located, the :meth:`pygmt.Figure.coast` method
99+
# can be used to color in the landmasses. The ``land`` is colored in as "lightgray", and
100+
# the ``shorelines`` parameter draws a border around the islands.
109101

110102
fig = pygmt.Figure()
111103
fig.grdimage(grid=grid, frame="a", projection="M10c", cmap="oleron")
@@ -119,25 +111,22 @@
119111
# Additional exercises
120112
# --------------------
121113
#
122-
# This is the end of the second tutorial. Here are some additional exercises
123-
# for the concepts that were discussed:
114+
# This is the end of the second tutorial. Here are some additional exercises for the
115+
# concepts that were discussed:
124116
#
125-
# 1. Change the resolution of the grid file to either ``"01m"`` (1 arc-minute,
126-
# a lower resolution) or ``"15s"`` (15 arc-seconds, a higher resolution).
127-
# Note that higher resolution grids will have larger file sizes. Available
128-
# resolutions can be found `here
129-
# <https://www.generic-mapping-tools.org/
130-
# remote-datasets/earth-relief.html#usage>`_.
117+
# 1. Change the resolution of the grid file to either ``"01m"`` (1 arc-minute, a lower
118+
# resolution) or ``"15s"`` (15 arc-seconds, a higher resolution). Note that higher
119+
# resolution grids will have larger file sizes. Available resolutions can be found
120+
# at :meth:`pygmt.datasets.load_earth_relief`.
131121
#
132122
# 2. Create a contour map of the area around Mt. Rainier. A suggestion for the
133123
# ``region`` would be ``[-122, -121, 46.5, 47.5]``. Adjust the
134-
# :meth:`pygmt.Figure.grdcontour` and :meth:`pygmt.Figure.colorbar`
135-
# settings as needed to make the figure look good.
124+
# :meth:`pygmt.Figure.grdcontour` and :meth:`pygmt.Figure.colorbar` settings as
125+
# needed to make the figure look good.
136126
#
137-
# 3. Create a contour map of São Miguel Island in the Azores; a suggested
138-
# ``region`` is ``[-26, -25, 37.5, 38]``. Instead of coloring in ``land``,
139-
# set ``water`` to "lightblue" to only display Earth relief information for
140-
# the land.
127+
# 3. Create a contour map of São Miguel Island in the Azores; a suggested ``region`` is
128+
# ``[-26, -25, 37.5, 38]``. Instead of coloring in ``land``, set ``water`` to
129+
# "lightblue" to only display Earth relief information for the land.
141130
#
142131
# 4. Try other CPTs, such as "SCM/fes" or "geo".
143132

examples/tutorials/advanced/contour_map.py

Lines changed: 23 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,11 @@
1616
# Create contour plot
1717
# -------------------
1818
#
19-
# The :meth:`pygmt.Figure.grdcontour` method takes the grid input.
20-
# It plots annotated contour lines, which are thicker and have the
21-
# elevation/depth written on them, and unannotated contour lines.
22-
# In the example below, the default contour line intervals are 500 meters,
23-
# with an annotated contour line every 1,000 meters.
24-
# By default, it plots the map with the
25-
# equidistant cylindrical projection and with no frame.
19+
# The :meth:`pygmt.Figure.grdcontour` method takes the grid input. It plots annotated
20+
# contour lines, which are thicker and have the elevation/depth written on them, and
21+
# unannotated contour lines. In the example below, the default contour line intervals
22+
# are 500 meters, with an annotated contour line every 1,000 meters. By default, it
23+
# plots the map with the equidistant cylindrical projection and with no frame.
2624

2725
fig = pygmt.Figure()
2826
fig.grdcontour(grid=grid)
@@ -33,45 +31,40 @@
3331
# Contour line settings
3432
# ---------------------
3533
#
36-
# Use the ``annotation`` and ``levels`` parameters to adjust contour line
37-
# intervals. In the example below, there are contour intervals every 250 meters
38-
# and annotated contour lines every 1,000 meters.
34+
# Use the ``annotation`` and ``levels`` parameters to adjust contour line intervals. In
35+
# the example below, there are contour intervals every 250 meters and annotated contour
36+
# lines every 1,000 meters.
3937

4038
fig = pygmt.Figure()
41-
fig.grdcontour(annotation=1000, levels=250, grid=grid)
39+
fig.grdcontour(grid=grid, annotation=1000, levels=250)
4240
fig.show()
4341

4442

4543
# %%
4644
# Contour limits
4745
# --------------
4846
#
49-
# The ``limit`` parameter sets the minimum and maximum values for the contour
50-
# lines. The parameter takes the low and high values, and is either a list (as
51-
# below) or a string ``limit="-4000/-2000"``.
47+
# The ``limit`` parameter sets the minimum and maximum values for the contour lines. The
48+
# parameter takes the low and high values, and is either a list (as below) or a string
49+
# ``limit="-4000/-2000"``.
5250

5351
fig = pygmt.Figure()
54-
fig.grdcontour(
55-
annotation=1000,
56-
levels=250,
57-
grid=grid,
58-
limit=[-4000, -2000],
59-
)
52+
fig.grdcontour(grid=grid, annotation=1000, levels=250, limit=[-4000, -2000])
6053
fig.show()
6154

6255

6356
# %%
6457
# Map settings
6558
# ------------
6659
#
67-
# The :meth:`pygmt.Figure.grdcontour` method accepts additional parameters,
68-
# including setting the projection and frame.
60+
# The :meth:`pygmt.Figure.grdcontour` method accepts additional parameters, including
61+
# setting the projection and frame.
6962

7063
fig = pygmt.Figure()
7164
fig.grdcontour(
65+
grid=grid,
7266
annotation=1000,
7367
levels=250,
74-
grid=grid,
7568
limit=[-4000, -2000],
7669
projection="M10c",
7770
frame=True,
@@ -83,27 +76,16 @@
8376
# Adding a colormap
8477
# -----------------
8578
#
86-
# The :meth:`pygmt.Figure.grdimage` method can be used to add a
87-
# colormap to the contour map. It must be called prior to
88-
# :meth:`pygmt.Figure.grdcontour` to keep the contour lines visible on the
89-
# final map. If the ``projection`` parameter is specified in the
79+
# The :meth:`pygmt.Figure.grdimage` method can be used to add a colormap to the contour
80+
# map. It must be called prior to :meth:`pygmt.Figure.grdcontour` to keep the contour
81+
# lines visible on the final map. If the ``projection`` parameter is specified in the
9082
# :meth:`pygmt.Figure.grdimage` method, it does not need to be repeated in the
91-
# :meth:`pygmt.Figure.grdcontour` method. Finally, a colorbar is added using
92-
# the :meth:`pygmt.Figure.colorbar` method.
83+
# :meth:`pygmt.Figure.grdcontour` method. Finally, a colorbar is added using the
84+
# :meth:`pygmt.Figure.colorbar` method.
9385

9486
fig = pygmt.Figure()
95-
fig.grdimage(
96-
grid=grid,
97-
cmap="haxby",
98-
projection="M10c",
99-
frame=True,
100-
)
101-
fig.grdcontour(
102-
annotation=1000,
103-
levels=250,
104-
grid=grid,
105-
limit=[-4000, -2000],
106-
)
87+
fig.grdimage(grid=grid, cmap="haxby", projection="M10c", frame=True)
88+
fig.grdcontour(grid=grid, annotation=1000, levels=250, limit=[-4000, -2000])
10789
fig.colorbar(frame=["x+lelevation", "y+lm"])
10890
fig.show()
10991

0 commit comments

Comments
 (0)