Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add tutorial for contour maps #705

Merged
merged 29 commits into from
Dec 1, 2020
Merged
Show file tree
Hide file tree
Changes from 28 commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
8c6e785
Add contour_map.py to new branch
willschlitzer Nov 25, 2020
26a019a
Rename file, add tutorial to index
willschlitzer Nov 25, 2020
f55f610
Update examples/tutorials/contour-map.py
willschlitzer Nov 25, 2020
ef61481
Update doc/index.rst
willschlitzer Nov 25, 2020
b45a1af
Update contour-map.py
willschlitzer Nov 25, 2020
82ac185
Update contour-map.py
willschlitzer Nov 25, 2020
42abe59
Update examples/tutorials/contour-map.py
willschlitzer Nov 28, 2020
d6c7dd8
Update examples/tutorials/contour-map.py
willschlitzer Nov 28, 2020
5c9b17c
Update examples/tutorials/contour-map.py
willschlitzer Nov 28, 2020
faa07cf
Update all example figures to use the grid variable for the grdcontou…
willschlitzer Nov 28, 2020
e6e9b4b
Update examples/tutorials/contour-map.py
willschlitzer Nov 29, 2020
0d33642
Update examples/tutorials/contour-map.py
willschlitzer Nov 29, 2020
bc13ac8
Update examples/tutorials/contour-map.py
willschlitzer Nov 29, 2020
eecd262
Update examples/tutorials/contour-map.py
willschlitzer Nov 29, 2020
e741862
Update examples/tutorials/contour-map.py
willschlitzer Nov 29, 2020
9b2db7d
Update examples/tutorials/contour-map.py
willschlitzer Nov 29, 2020
14aeb7b
Update examples/tutorials/contour-map.py
willschlitzer Nov 29, 2020
bab041e
Update examples/tutorials/contour-map.py
willschlitzer Nov 29, 2020
92cfc0e
Update comments to keep lines at or below 88 characters
willschlitzer Nov 29, 2020
8def635
Add example code and explanation for creating a contour map with color
willschlitzer Nov 29, 2020
317fd87
Update examples/tutorials/contour-map.py
willschlitzer Nov 29, 2020
eca4c6a
Update examples/tutorials/contour-map.py
willschlitzer Nov 29, 2020
d5f4e52
Update examples/tutorials/contour-map.py
willschlitzer Nov 29, 2020
e39dc7e
Update examples/tutorials/contour-map.py
willschlitzer Nov 29, 2020
020e30f
Rephrasing colormap comments when describing projection argument
willschlitzer Nov 29, 2020
ebdd34c
Changing region and using 05m resolution vs. 15s
willschlitzer Nov 29, 2020
572a586
Merge branch 'master' into contour-map
willschlitzer Nov 30, 2020
a3c25cd
Update limit high value to -2000 m vs. 0 m
willschlitzer Nov 30, 2020
6e7d40b
Merge branch 'master' into contour-map
willschlitzer Dec 1, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions doc/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
tutorials/coastlines.rst
tutorials/plot.rst
tutorials/text.rst
tutorials/contour-map.rst
tutorials/configuration.rst

.. toctree::
Expand Down
104 changes: 104 additions & 0 deletions examples/tutorials/contour-map.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
"""
Creating a map with contour lines
=================================

Plotting a contour map is handled by :meth:`pygmt.Figure.grdcontour`.
"""

import pygmt
willschlitzer marked this conversation as resolved.
Show resolved Hide resolved

# Load sample earth relief data
grid = pygmt.datasets.load_earth_relief(resolution="05m", region=[-92.5, -82.5, -3, 7])

########################################################################################
# Create contour plot
# -------------------
#
# The :meth:`pygmt.Figure.grdcontour` method takes the grid input.
# It plots annotated contour lines, which are thicker and have the
# elevation/depth written on them, and unannotated contour lines.
# In the example below, the default contour line intervals are 500 meters,
# with an annotated contour line every 1000 meters.
# By default, it plots the map with the
# equidistant cylindrical projection and with no frame.

fig = pygmt.Figure()
fig.grdcontour(grid=grid)
fig.show()

########################################################################################
# Contour line settings
# ---------------------
#
# Use the ``annotation`` and ``interval`` arguments to adjust contour line intervals.
# In the example below, there are contour intervals every 250 meters and
# annotated contour lines every 1,000 meters.

fig = pygmt.Figure()
fig.grdcontour(
annotation=1000,
interval=250,
grid=grid,
)
fig.show()

########################################################################################
# Contour limits
# --------------
#
# The ``limit`` argument sets the minimum and maximum values for the contour lines.
# The argument takes the low and high values,
# and is either a list (as below) or a string ``limit="-4000/-2000"``.

fig = pygmt.Figure()
fig.grdcontour(
annotation=1000,
interval=250,
grid=grid,
limit=[-4000, -2000],
)
fig.show()

########################################################################################
# Map settings
# ------------
#
# The :meth:`pygmt.Figure.grdcontour` method accepts additional arguments,
# including setting the projection and frame.

fig = pygmt.Figure()
fig.grdcontour(
annotation=1000,
interval=250,
grid=grid,
limit=[-4000, -2000],
projection="M4i",
frame=True,
)
fig.show()

########################################################################################
# Adding a colormap
# -----------------
#
# The :meth:`pygmt.Figure.grdimage` method can be used to add a
# colormap to the contour map. It must be called prior to
# :meth:`pygmt.Figure.grdcontour` to keep the contour lines visible on the final map.
# If the ``projection`` argument is specified in the :meth:`pygmt.Figure.grdimage`
# method, it does not need to be repeated in
# the :meth:`pygmt.Figure.grdcontour` method.

fig = pygmt.Figure()
fig.grdimage(
grid=grid,
cmap="haxby",
projection="M4i",
frame=True,
)
fig.grdcontour(
annotation=1000,
interval=250,
grid=grid,
limit=[-4000, -2000],
)
fig.show()