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 inline example for grdview #2381

Merged
merged 9 commits into from
Mar 23, 2023
35 changes: 35 additions & 0 deletions pygmt/src/grdview.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
use_alias,
)

__doctest_skip__ = ["grdview"]


@fmt_docstring
@use_alias(
Expand Down Expand Up @@ -117,6 +119,39 @@ def grdview(self, grid, **kwargs):
{interpolation}
{perspective}
{transparency}

Example
-------
>>> import pygmt
>>> # load the 30 arc-minutes grid with "gridline" registration
>>> # in a specified region
>>> grid = pygmt.datasets.load_earth_relief(
... resolution="30m",
... region=[-92.5, -82.5, -3, 7],
... registration="gridline",
... )
>>> # create a new figure instance with pygmt.Figure()
>>> fig = pygmt.Figure()
>>> # create the contour plot
>>> fig.grdview(
... # pass in the grid downloaded above
... grid=grid,
... # set the perspective to an azimuth of 130° and an elevation of 30°
... perspective=[130, 30],
... # add a frame to the x- and y-axes
... # specify annotations on the south and east borders of the plot
... frame=["xa", "ya", "wSnE"],
... # set the projection to Mercator for the 10 cm wide figure
seisman marked this conversation as resolved.
Show resolved Hide resolved
... projection="M10c",
yvonnefroehlich marked this conversation as resolved.
Show resolved Hide resolved
... # set the vertical scale (z-axis) to 2 cm
... zsize="2c",
... # set "surface plot" to color the surface via a CPT
... surftype="s",
... # specify CPT to "geo"
... cmap="geo",
... )
>>> # show the plot
>>> fig.show()
"""
kwargs = self._preprocess(**kwargs) # pylint: disable=protected-access
with Session() as lib:
Expand Down