Skip to content

Commit bcffeb2

Browse files
committed
Introduce grdview aliases cmap for C and surftype for Q
Giving our grdview wrapper the ability to color plots! The cmap (C) parameter (which stands for colormap) should be straightforward, while the surftype (Q) parameter is a little bit more complicated. Some more tests added to check that we can indeed produce colored perspective-view plots.
1 parent 01fd955 commit bcffeb2

5 files changed

+67
-1
lines changed

pygmt/base_plotting.py

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -233,12 +233,26 @@ def grdimage(self, grid, **kwargs):
233233
lib.call_module("grdimage", arg_str)
234234

235235
@fmt_docstring
236-
@use_alias(R="region", J="projection", Jz="zscale", JZ="zsize", p="perspective")
236+
@use_alias(
237+
R="region",
238+
J="projection",
239+
Jz="zscale",
240+
JZ="zsize",
241+
C="cmap",
242+
Q="surftype",
243+
p="perspective",
244+
)
237245
@kwargs_to_strings(R="sequence", p="sequence")
238246
def grdview(self, reliefgrid, **kwargs):
239247
"""
240248
Create 3-D perspective image or surface mesh from a grid.
241249
250+
Reads a 2-D grid file and produces a 3-D perspective plot by drawing a mesh,
251+
painting a colored/gray-shaded surface made up of polygons, or by scanline
252+
conversion of these polygons to a raster image. Options include draping a data
253+
set on top of a surface, plotting of contours on top of the surface, and apply
254+
artificial illumination based on intensities provided in a separate grid file.
255+
242256
Full option list at :gmt-docs:`grdview.html`
243257
244258
Parameters
@@ -249,6 +263,19 @@ def grdview(self, reliefgrid, **kwargs):
249263
zscale (Jz) or zsize (JZ) : float or str
250264
Set z-axis scaling or z-axis size.
251265
266+
cmap (C) : str
267+
The name of the color palette table to use.
268+
269+
surftype (Q) : str
270+
Specifies cover type of the reliefgrid. Select one of following settings:
271+
1. 'm' for mesh plot [Default].
272+
2. 'mx' or 'my' for waterfall plots (row or column profiles).
273+
3. 's' for surface plot.
274+
4. 'i' for image plot.
275+
5. 'c'. Same as 'i' but will make nodes with z = NaN transparent.
276+
For any of these choices, you may force a monochrome image by appending the
277+
modifier +m.
278+
252279
perspective (p) : list or str
253280
``'[x|y|z]azim[/elev[/zlevel]][+wlon0/lat0[/z0]][+vx0/y0]'``.
254281
Select perspective view.
Loading
Loading
Loading

pygmt/tests/test_grdview.py

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,3 +83,42 @@ def test_grdview_with_perspective_and_zsize(grid):
8383
fig = Figure()
8484
fig.grdview(reliefgrid=grid, perspective=[225, 30], zsize="10c")
8585
return fig
86+
87+
88+
@pytest.mark.mpl_image_compare
89+
def test_grdview_with_cmap_for_image_plot(grid):
90+
"""
91+
Run grdview by passing in a reliefgrid and setting a colormap for producing an image
92+
plot.
93+
"""
94+
fig = Figure()
95+
fig.grdview(reliefgrid=grid, cmap="oleron", surftype="i")
96+
return fig
97+
98+
99+
@pytest.mark.mpl_image_compare
100+
def test_grdview_with_cmap_for_surface_monochrome_plot(grid):
101+
"""
102+
Run grdview by passing in a reliefgrid and setting a colormap for producing a
103+
surface monochrome plot.
104+
"""
105+
fig = Figure()
106+
fig.grdview(reliefgrid=grid, cmap="oleron", surftype="s+m")
107+
return fig
108+
109+
110+
@pytest.mark.mpl_image_compare
111+
def test_grdview_with_cmap_for_perspective_surface_plot(grid):
112+
"""
113+
Run grdview by passing in a reliefgrid and setting a colormap for producing a
114+
surface plot with a 3D perspective viewpoint.
115+
"""
116+
fig = Figure()
117+
fig.grdview(
118+
reliefgrid=grid,
119+
cmap="oleron",
120+
surftype="s",
121+
perspective=[225, 30],
122+
zscale=0.005,
123+
)
124+
return fig

0 commit comments

Comments
 (0)