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 plotting Earth relief #712

Merged
merged 45 commits into from
Dec 10, 2020
Merged
Show file tree
Hide file tree
Changes from 12 commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
1b54a14
Create example for basic plot with color pallete
willschlitzer Dec 1, 2020
96241c8
Add example code for setting frame and projection in grdimage figure
willschlitzer Dec 1, 2020
46a773a
Add example showing inclusion of color bar
willschlitzer Dec 1, 2020
0ba35b2
Add setting cmap argument
willschlitzer Dec 1, 2020
fa16924
Add custom color pallete example
willschlitzer Dec 1, 2020
2c41655
Add color-figure.rst to index.rst
willschlitzer Dec 1, 2020
90c8d9f
Move color-figure.rst to bottom of list in index.rst to avoid merge c…
willschlitzer Dec 1, 2020
c24f948
Merge branch 'master' into color-figure
willschlitzer Dec 1, 2020
ca4d016
Fix typo
willschlitzer Dec 1, 2020
5faee47
Expanding comment
willschlitzer Dec 1, 2020
9e7b463
Updating colorbar labels and changing color pallete intervals
willschlitzer Dec 1, 2020
7ab9264
Add color bar frame settings; reorder continuous/discrete color palle…
willschlitzer Dec 2, 2020
39dfffd
Update examples/tutorials/color-figure.py
willschlitzer Dec 2, 2020
e8d397e
Fix "pallete" to "palette"
willschlitzer Dec 2, 2020
600f216
Update doc/index.rst
willschlitzer Dec 3, 2020
547ca69
Changing tutorial title
willschlitzer Dec 5, 2020
9bb5d4b
Remove portion of tutorial for making custom CPT
willschlitzer Dec 5, 2020
c591bda
Add basic plotting for Earth relief using grdimage
willschlitzer Dec 7, 2020
2e79dd2
Delete unused portion of tutorial
willschlitzer Dec 7, 2020
26e35db
Merge branch 'master' into color-figure
willschlitzer Dec 7, 2020
0af7c07
Add section divider
willschlitzer Dec 7, 2020
663dd42
Adding figures with CPTs example
willschlitzer Dec 7, 2020
a2052bb
Add example for color bar
willschlitzer Dec 7, 2020
29a24f4
Creating a regional map example
willschlitzer Dec 7, 2020
b5b738b
Fix formatting typos
willschlitzer Dec 7, 2020
82c5e29
Update examples/tutorials/color-figure.py
willschlitzer Dec 8, 2020
939b8f4
Update examples/tutorials/color-figure.py
willschlitzer Dec 8, 2020
4d1f836
Update examples/tutorials/color-figure.py
willschlitzer Dec 8, 2020
4fabe33
Update examples/tutorials/color-figure.py
willschlitzer Dec 8, 2020
eb5034c
Update examples/tutorials/color-figure.py
willschlitzer Dec 8, 2020
9b01bb6
Update examples/tutorials/color-figure.py
willschlitzer Dec 8, 2020
9e79e04
Rename color-figure.py to earth-relief.py; update index.rst
willschlitzer Dec 8, 2020
2b8b8a4
Changing units to SI units in projections in descriptions
willschlitzer Dec 8, 2020
d9a8bed
Fix typo with unit
willschlitzer Dec 8, 2020
5fea74d
Update examples/tutorials/earth-relief.py
willschlitzer Dec 8, 2020
2a4957a
Update examples/tutorials/earth-relief.py
willschlitzer Dec 8, 2020
6600397
Update examples/tutorials/earth-relief.py
willschlitzer Dec 8, 2020
cc7cdbc
Update examples/tutorials/earth-relief.py
willschlitzer Dec 8, 2020
9b71adb
Update examples/tutorials/earth-relief.py
willschlitzer Dec 8, 2020
98547cb
Update examples/tutorials/earth-relief.py
willschlitzer Dec 8, 2020
0432727
Update examples/tutorials/earth-relief.py
willschlitzer Dec 8, 2020
94267b3
Update examples/tutorials/earth-relief.py
willschlitzer Dec 8, 2020
e3f4c23
Update examples/tutorials/earth-relief.py
willschlitzer Dec 8, 2020
ed96a57
Update examples/tutorials/earth-relief.py
willschlitzer Dec 8, 2020
92f6100
Merge branch 'master' into color-figure
willschlitzer Dec 8, 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 @@ -35,6 +35,7 @@
tutorials/text.rst
tutorials/contour-map.rst
tutorials/configuration.rst
tutorials/color-figure.rst

.. toctree::
:maxdepth: 2
Expand Down
95 changes: 95 additions & 0 deletions examples/tutorials/color-figure.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
"""
Adding a color pallete to a figure
==================================

Plotting a map with a color pallete is handled by :meth:`pygmt.Figure.grdimage`. The
:meth:`pygmt.makecpt` method creates a custom color pallete that can be used with
the figures and color bars.
"""

import pygmt

# Load sample earth relief data
grid = pygmt.datasets.load_earth_relief(resolution="05m", region=[-86, -64, 17, 24])

########################################################################################
# Create a plot with color
# ------------------------
#
# The :meth:`pygmt.Figure.grdimage` method takes the ``grid`` input and optional
# ``region`` argument to create a figure. It creates and applies a color pallete to the
# figure based upon the z-values of the data. By default, it plots the map with the
# equidistant cylindrical projection and with no frame.

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

########################################################################################
# A specific color pallete can be set using the optional ``cmap`` argument for
# :meth:`pygmt.Figure.grdimage`. By default, the color pallete is set to *turbo*.
# In the example below, the color pallete is set to *geo*.
# The full list of color palette tables can be found at :gmt-docs:`cookbook/cpts.html`.

fig = pygmt.Figure()
fig.grdimage(grid=grid, cmap="geo")
fig.show()

########################################################################################
# :meth:`pygmt.Figure.grdimage` accepts additional parameters, including ``frame`` and
# ``projection``.

fig = pygmt.Figure()
fig.grdimage(grid=grid, frame=True, projection="M6i", cmap="geo")
fig.show()

########################################################################################
# The :meth:`pygmt.Figure.colorbar` method can be used to add a color bar to the figure.
# By default, it applies the color pallete created by :meth:`pygmt.Figure.grdimage`.
#
# The `frame` argument can be used to set the color bar labels and intervals.
# In the example below, ``p3000`` sets the color bar tick interval to 3,000 meters,
# and ``x+lElevation`` and ``y+lm`` set the x- and y-axis labels for the color bar.

fig = pygmt.Figure()
fig.grdimage(grid=grid, frame=True, projection="M6i", cmap="geo")
fig.colorbar(frame=["p3000", "x+lElevation", "y+lm"])
fig.show()

########################################################################################
# Create a custom color pallete
# -----------------------------
#
# The :meth:`pygmt.makecpt` method provides the option to create a custom color pallete
# for a figure. The ``cmap`` argument sets the master color pallete to base the
# new color pallete on. The ``series`` argument sets the minimum and maximum values, and
# optionally the intervals between them; without it, the new color pallete defaults to
# the min/max values of the master color pallete. The ``series`` argument can be given
# as a string (as below) or as a list ``series=[-8500, 2500, 1000]``. Any values that
# fall outside the range of the series will be plotted as black (lower than the minimum)
# or white (higher than the maximum).
#
# The :meth:`pygmt.makecpt` method includes an ``output`` parameter, which allows the
# custom color pallete to be saved in a .cpt file. It's default value is False, which
# uses the custom color pallete as the default color pallete for
# the figure and color bar.

fig = pygmt.Figure()
pygmt.makecpt(cmap="jet", series="-9000/3000", continuous=True)
fig.grdimage(grid=grid, projection="M6i", frame=True)
fig.colorbar(frame=["p3000", "x+lElevation", "y+lm"])
fig.show()

########################################################################################
# The ``continuous`` argument forces the custom color pallete to be continuous or
# discrete. Discrete color palletes will have a single color for a range of values
# within the color pallete, while continuous color palletes will assign a different
# color for every value in its series. The ``series`` argument requires an interval
# setting to create a discrete color pallete, or it will default to a
# continuous color pallete.

fig = pygmt.Figure()
pygmt.makecpt(cmap="jet", series="-9000/3000/1500", continuous=False)
fig.grdimage(grid=grid, projection="M6i", frame=True)
fig.colorbar(frame=["p1500", "x+lElevation", "y+lm"])
fig.show()