Skip to content

Commit 06ee20e

Browse files
committed
Figure.grdview: Improve parameters 'plane'/'facadefill'/'facadepen' to set the plane and facade
1 parent 2b395fa commit 06ee20e

File tree

5 files changed

+51
-15
lines changed

5 files changed

+51
-15
lines changed

examples/tutorials/advanced/3d_perspective_image.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,8 @@
5555
fig.show()
5656

5757
# %%
58-
# The ``plane`` parameter sets the elevation and color of a plane that provides
59-
# a fill below the surface relief.
58+
# The ``plane`` parameter sets the elevation and color of a plane that provides a fill
59+
# below the surface relief.
6060

6161
fig = pygmt.Figure()
6262
fig.grdview(
@@ -67,8 +67,8 @@
6767
zsize="1.5c",
6868
surftype="s",
6969
cmap="geo",
70-
# Set the plane elevation to 1,000 meters and make the fill "gray"
71-
plane="1000+ggray",
70+
plane=1000, # Set the plane elevation to 1,000 meters
71+
facade_fill="gray", # Fill the facade with "gray"
7272
)
7373
fig.show()
7474

@@ -90,7 +90,8 @@
9090
zsize="1.5c",
9191
surftype="s",
9292
cmap="geo",
93-
plane="1000+ggrey",
93+
plane=1000,
94+
facade_fill="gray",
9495
# Set the contour pen thickness to "0.1p"
9596
contour_pen="0.1p",
9697
)

examples/tutorials/advanced/draping_on_3d_surface.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@
6565
shading="+a0/270+ne0.6",
6666
perspective=[157.5, 30], # Azimuth and elevation for the 3-D plot
6767
zsize="1.5c",
68-
plane="+gdarkgray",
68+
facade_fill="darkgray",
6969
frame=True,
7070
)
7171

@@ -128,7 +128,7 @@
128128
shading="+a0/270+ne0.6",
129129
perspective=[157.5, 30], # Define azimuth, elevation for the 3-D plot
130130
zsize="1c",
131-
plane="+gdarkgray",
131+
facade_fill="darkgray",
132132
frame=True,
133133
)
134134

pygmt/src/grdview.py

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
@use_alias(
2222
C="cmap",
2323
G="drapegrid",
24-
N="plane",
2524
Q="surftype",
2625
I="shading",
2726
f="coltypes",
@@ -31,8 +30,10 @@ def grdview( # noqa: PLR0913
3130
self,
3231
grid: PathLike | xr.DataArray,
3332
contour_pen: str | None = None,
34-
facade_pen: str | None = None,
3533
mesh_pen: str | None = None,
34+
plane: float | bool = False,
35+
facade_fill: str | None = None,
36+
facade_pen: str | None = None,
3637
projection: str | None = None,
3738
zscale: float | str | None = None,
3839
zsize: float | str | None = None,
@@ -61,6 +62,7 @@ def grdview( # noqa: PLR0913
6162
- J = projection
6263
- Jz = zscale
6364
- JZ = zsize
65+
- N = plane, facade_fill
6466
- R = region
6567
- V = verbose
6668
- Wc = contour_pen
@@ -90,11 +92,16 @@ def grdview( # noqa: PLR0913
9092
Note that ``zscale`` and ``plane`` always refer to ``grid``. ``drapegrid`` only
9193
provides the information pertaining to colors, which (if ``drapegrid`` is a
9294
grid) will be looked-up via the CPT (see ``cmap``).
93-
plane : float or str
94-
*level*\ [**+g**\ *fill*].
95-
Draw a plane at this z-level. If the optional color is provided via the **+g**
96-
modifier, and the projection is not oblique, the frontal facade between the
97-
plane and the data perimeter is colored.
95+
plane
96+
Draw a plane at the specified z-level. If ``True``, default to the minimum value
97+
in the grid. However, if ``region`` was used to set zmin/zmax then that value is
98+
used if it is less than the grid minimum value. Use ``facade_pen`` and
99+
``facade_fill`` to control the appearance of the plane.
100+
facade_fill
101+
Fill for the frontal facade between the plane specified by ``plane`` and the
102+
data perimeter.
103+
facade_pen
104+
Set the pen attributes used for the facade.
98105
surftype : str
99106
Specify cover type of the grid. Select one of following settings:
100107
@@ -165,9 +172,17 @@ def grdview( # noqa: PLR0913
165172
"""
166173
self._activate_figure()
167174

175+
# Enable 'plane' if 'facade_fill' or 'facade_pen' is set
176+
if plane is False and (facade_fill is not None or facade_pen is not None):
177+
plane = True
178+
168179
aliasdict = AliasSystem(
169180
Jz=Alias(zscale, name="zscale"),
170181
JZ=Alias(zsize, name="zsize"),
182+
N=[
183+
Alias(plane, name="plane"),
184+
Alias(facade_fill, name="facade_fill", prefix="+g"),
185+
],
171186
Wc=Alias(contour_pen, name="contour_pen"),
172187
Wf=Alias(facade_pen, name="facade_pen"),
173188
Wm=Alias(mesh_pen, name="mesh_pen"),
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
outs:
2+
- md5: cfff4879fbe7ab03d8a304b2622b9782
3+
size: 26208
4+
hash: md5
5+
path: test_grdview_facadepen_default_plane.png

pygmt/tests/test_grdview.py

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,9 @@ def test_grdview_on_a_plane_with_colored_frontal_facade(xrgrid):
150150
is colored gray, while setting a 3-D perspective viewpoint.
151151
"""
152152
fig = Figure()
153-
fig.grdview(grid=xrgrid, plane="100+ggray", perspective=[225, 30], zscale=0.005)
153+
fig.grdview(
154+
grid=xrgrid, plane=100, facade_fill="gray", perspective=[225, 30], zscale=0.005
155+
)
154156
return fig
155157

156158

@@ -211,6 +213,19 @@ def test_grdview_on_a_plane_styled_with_facadepen(xrgrid):
211213
return fig
212214

213215

216+
@pytest.mark.mpl_image_compare
217+
def test_grdview_facadepen_default_plane(xrgrid):
218+
"""
219+
Run grdview by passing in a grid and plotting it on the default z-plane with styled
220+
lines for the frontal facade.
221+
"""
222+
fig = Figure()
223+
fig.grdview(
224+
grid=xrgrid, perspective=[225, 30], zscale=0.005, facade_pen="0.5p,blue,dash"
225+
)
226+
return fig
227+
228+
214229
@pytest.mark.benchmark
215230
@pytest.mark.mpl_image_compare
216231
def test_grdview_drapegrid_dataarray(xrgrid):

0 commit comments

Comments
 (0)