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 3D perspective image #743

Merged
merged 23 commits into from
Dec 20, 2020
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
72a8506
Create mesh plot in 3d-map.py
willschlitzer Dec 17, 2020
f676441
Add set surftype
willschlitzer Dec 17, 2020
0473e77
Complete 3D map tutorial
willschlitzer Dec 17, 2020
e5c993c
Update 3d-map.py
willschlitzer Dec 17, 2020
070db1e
Update index.rst
willschlitzer Dec 17, 2020
6ba0dca
Update examples/tutorials/3d-map.py
willschlitzer Dec 19, 2020
153846b
Change title and docstring
willschlitzer Dec 19, 2020
0c7fc77
Change perspective azimuth
willschlitzer Dec 19, 2020
5bdbab7
Change comment for default grid surface type
willschlitzer Dec 19, 2020
e1bee06
Change surftype comment
willschlitzer Dec 19, 2020
9daba6e
Explain plane parameter in comment
willschlitzer Dec 19, 2020
f507544
Merge branch 'master' into 3d-map-tutorial
willschlitzer Dec 19, 2020
3e9539b
Minor format fixes; remove repeat comment
willschlitzer Dec 19, 2020
d79cecd
Update examples/tutorials/3d-map.py
willschlitzer Dec 20, 2020
17bfc80
Update examples/tutorials/3d-map.py
willschlitzer Dec 20, 2020
9a1065b
Update examples/tutorials/3d-map.py
willschlitzer Dec 20, 2020
e824868
Update examples/tutorials/3d-map.py
willschlitzer Dec 20, 2020
ffc621e
Update examples/tutorials/3d-map.py
willschlitzer Dec 20, 2020
1d50cfa
Update examples/tutorials/3d-map.py
willschlitzer Dec 20, 2020
e72c1d5
Update examples/tutorials/3d-map.py
willschlitzer Dec 20, 2020
6d2a3d9
Merge branch 'master' into 3d-map-tutorial
willschlitzer Dec 20, 2020
e73e212
Rename 3d-map.py to 3d-perspective-image.py and change index
willschlitzer Dec 20, 2020
16e8673
Rephrase comment to show reason for passing perspective=True
willschlitzer Dec 20, 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/earth-relief.rst
tutorials/3d-map.rst
willschlitzer marked this conversation as resolved.
Show resolved Hide resolved
tutorials/configuration.rst

.. toctree::
Expand Down
140 changes: 140 additions & 0 deletions examples/tutorials/3d-map.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
"""
Creating a 3D map
=================

Plotting a three-dimensional map is handled by :meth:`pygmt.Figure.grdview`.
willschlitzer marked this conversation as resolved.
Show resolved Hide resolved
"""

import pygmt

# Load sample earth relief data
grid = pygmt.datasets.load_earth_relief(resolution="05m", region=[-108, -103, 35, 40])

########################################################################################
# The :meth:`pygmt.Figure.grdview` method takes the ``grid`` input.
# The ``perspective`` argument changes the azimuth and angle of the viewpoint; the
willschlitzer marked this conversation as resolved.
Show resolved Hide resolved
# default is [180, 90], which is looking directly down on the figure and north is "up".
# The ``zsize`` argument sets how tall the three-dimensional portion appears.
#
# The default figure surface is *mesh plot*.
willschlitzer marked this conversation as resolved.
Show resolved Hide resolved

fig = pygmt.Figure()
fig.grdview(
grid=grid,
# Sets the view azimuth as 180 degrees, and the view angle as 30 degrees
perspective=[180, 30],
willschlitzer marked this conversation as resolved.
Show resolved Hide resolved
# Sets the x- and y-axis labels, and annotates the west, south, and east axes
frame=["xa", "ya", "WSnE"],
# Sets a Mercator projection on a 15-centimeter figure
projection="M15c",
# Sets the height of the three-dimensional relief at 1.5 centimeters
zsize="1.5c",
)
fig.show()

########################################################################################
# The figure surface type can be set with the ``surftype`` parameter.
willschlitzer marked this conversation as resolved.
Show resolved Hide resolved
# The default CPT is *turbo*.
willschlitzer marked this conversation as resolved.
Show resolved Hide resolved

fig = pygmt.Figure()
fig.grdview(
grid=grid,
perspective=[180, 30],
frame=["xa", "ya", "WSnE"],
projection="M15c",
zsize="1.5c",
# Sets the surface type to solid
willschlitzer marked this conversation as resolved.
Show resolved Hide resolved
surftype="s",
)
fig.show()

########################################################################################
# The CPT can be set with the ``cmap`` parameter.
willschlitzer marked this conversation as resolved.
Show resolved Hide resolved

fig = pygmt.Figure()
fig.grdview(
grid=grid,
perspective=[180, 30],
frame=["xa", "yaf", "WSnE"],
projection="M15c",
zsize="1.5c",
surftype="s",
# Set the CPT to "geo"
cmap="geo",
)
fig.show()

########################################################################################
# The ``plane`` argument sets the elevation and color of a plane that provides a fill
# below the surface relief.

fig = pygmt.Figure()
fig.grdview(
grid=grid,
perspective=[180, 30],
frame=["xa", "yaf", "WSnE"],
projection="M15c",
zsize="1.5c",
surftype="s",
cmap="geo",
willschlitzer marked this conversation as resolved.
Show resolved Hide resolved
plane="1000+ggrey",
)
fig.show()

########################################################################################
# The ``perspective`` azimuth can be changed to set the direction that is "up"
# in the figure.

fig = pygmt.Figure()
fig.grdview(
grid=grid,
# Set the azimuth to 135 degrees and the angle to 30 degrees
willschlitzer marked this conversation as resolved.
Show resolved Hide resolved
perspective=[135, 30],
frame=["xa", "yaf", "WSnE"],
projection="M15c",
zsize="1.5c",
surftype="s",
cmap="geo",
# Set the elevation of the plane at 1,000 meters and the color to grey
plane="1000+ggrey",
)
fig.show()

########################################################################################
# The ``contourpen`` parameter sets the pen used to draw contour lines on the surface.

fig = pygmt.Figure()
fig.grdview(
grid=grid,
perspective=[135, 30],
frame=["xaf", "yaf", "WSnE"],
projection="M15c",
zsize="1.5c",
surftype="s",
cmap="geo",
plane="1000+ggrey",
# Set the contour pen thickness to "0.5p"
contourpen="0.5p",
)
fig.show()

########################################################################################
# :meth:`pygmt.Figure.colorbar` can be used to add a color bar to the figure. The
# ``cmap`` argument does not need to be passed again. To keep the color bar's alignment
# similar to the figure, it also takes a ``perspective`` argument.
willschlitzer marked this conversation as resolved.
Show resolved Hide resolved

fig = pygmt.Figure()
perspective = [135, 30]
fig.grdview(
grid=grid,
perspective=perspective,
frame=["xaf", "yaf", "WSnE"],
projection="M15c",
zsize="1.5c",
surftype="s",
cmap="geo",
plane="1000+ggrey",
contourpen="0.1p",
)
fig.colorbar(perspective=perspective, frame=["a500", "x+lElevation", "y+lm"])
fig.show()