-
Notifications
You must be signed in to change notification settings - Fork 228
Add gallery example for grdview #502
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
Merged
liamtoney
merged 6 commits into
GenericMappingTools:master
from
liamtoney:grdview-gallery
Jul 2, 2020
Merged
Changes from 5 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
3b86d2d
Add gallery example for grdview
liamtoney 3ef7d8b
Add second line before function definition
liamtoney cfd8abf
Fix incorrect method syntax
liamtoney e70f8fb
Use "meth" instead of "func"
liamtoney 402899c
import xarray as xr
liamtoney 3b2392e
Finish updating to use xr
liamtoney File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
""" | ||
Plotting a surface | ||
------------------ | ||
|
||
The :meth:`pygmt.Figure.grdview()` method can plot 3-D surfaces with ``surftype="s"``. Here, | ||
we supply the data as an :class:`xarray.DataArray` with the coordinate vectors ``x`` and | ||
``y`` defined. Note that the ``perspective`` argument here controls the azimuth and | ||
elevation angle of the view. We provide a list of two arguments to ``frame`` — the | ||
second argument, prepended with ``"z"``, specifies the :math:`z`-axis frame attributes. | ||
Specifying the same scale for the ``projection`` and ``zcale`` arguments ensures equal | ||
axis scaling. | ||
""" | ||
|
||
import pygmt | ||
import numpy as np | ||
import xarray as xr | ||
|
||
|
||
# Define an interesting function of two variables, see: | ||
# https://en.wikipedia.org/wiki/Ackley_function | ||
def ackley(x, y): | ||
return ( | ||
-20 * np.exp(-0.2 * np.sqrt(0.5 * (x ** 2 + y ** 2))) | ||
- np.exp(0.5 * (np.cos(2 * np.pi * x) + np.cos(2 * np.pi * y))) | ||
+ np.exp(1) | ||
+ 20 | ||
) | ||
|
||
|
||
# Create gridded data | ||
INC = 0.05 | ||
x = np.arange(-5, 5 + INC, INC) | ||
y = np.arange(-5, 5 + INC, INC) | ||
data = xarray.DataArray(ackley(*np.meshgrid(x, y)), coords=(x, y)) | ||
liamtoney marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
fig = pygmt.Figure() | ||
|
||
# Plot grid as a 3-D surface | ||
SCALE = 0.2 # [inches] | ||
fig.grdview( | ||
data, | ||
frame=["a5f1", "za5f1"], | ||
projection=f"x{SCALE}i", | ||
zscale=f"{SCALE}i", | ||
surftype="s", | ||
cmap="roma", | ||
perspective="135/30", | ||
) | ||
|
||
fig.show() |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.