Skip to content

Commit 8caf8f5

Browse files
seismanyvonnefroehlichmichaelgrund
authored
Figure.grdview: Improve parameters plane/facade_fill/facade_pen to set the plane and facade (#4235)
Co-authored-by: Yvonne Fröhlich <94163266+yvonnefroehlich@users.noreply.github.com> Co-authored-by: Michael Grund <23025878+michaelgrund@users.noreply.github.com>
1 parent 38b4d07 commit 8caf8f5

File tree

5 files changed

+52
-19
lines changed

5 files changed

+52
-19
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", # Color the facade in "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.1 points
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: 23 additions & 11 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,6 @@ 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.
9895
surftype : str
9996
Specify cover type of the grid. Select one of following settings:
10097
@@ -110,13 +107,20 @@ def grdview( # noqa: PLR0913
110107
contour_pen
111108
Draw contour lines on top of surface or mesh (not image). Append pen attributes
112109
used for the contours.
113-
facade_pen
114-
Set the pen attributes used for the facade. You must also select ``plane`` for
115-
the facade outline to be drawn.
116110
mesh_pen
117111
Set the pen attributes used for the mesh. You must also select ``surftype`` of
118112
**m** or **sm** for meshlines to be drawn.
119-
shading : str
113+
plane
114+
Draw a plane at the specified z-level. If ``True``, defaults to the minimum
115+
value in the grid. However, if ``region`` was used to set *zmin/zmax* then
116+
*zmin* is used if it is less than the grid minimum value. Use ``facade_pen`` and
117+
``facade_fill`` to control the appearance of the plane.
118+
facade_fill
119+
Fill for the frontal facade between the plane specified by ``plane`` and the
120+
data perimeter.
121+
facade_pen
122+
Set the pen attributes used for the facade.
123+
shading : str or float
120124
Provide the name of a grid file with intensities in the (-1,+1) range, or a
121125
constant intensity to apply everywhere (affects the ambient light).
122126
Alternatively, derive an intensity grid from the main input data grid by using
@@ -165,9 +169,17 @@ def grdview( # noqa: PLR0913
165169
"""
166170
self._activate_figure()
167171

172+
# Enable 'plane' if 'facade_fill' or 'facade_pen' are set
173+
if plane is False and (facade_fill is not None or facade_pen is not None):
174+
plane = True
175+
168176
aliasdict = AliasSystem(
169177
Jz=Alias(zscale, name="zscale"),
170178
JZ=Alias(zsize, name="zsize"),
179+
N=[
180+
Alias(plane, name="plane"),
181+
Alias(facade_fill, name="facade_fill", prefix="+g"),
182+
],
171183
Wc=Alias(contour_pen, name="contour_pen"),
172184
Wf=Alias(facade_pen, name="facade_pen"),
173185
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

@@ -213,6 +215,19 @@ def test_grdview_on_a_plane_styled_with_facadepen(xrgrid):
213215
return fig
214216

215217

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

0 commit comments

Comments
 (0)