Skip to content

Commit 37a2e44

Browse files
authored
Figure.grdview: Fix the default z-plane to the grid z minimum when plane is set to True or only facede_fill/facede_pen is set (#4287)
1 parent 9a84653 commit 37a2e44

File tree

2 files changed

+19
-3
lines changed

2 files changed

+19
-3
lines changed

pygmt/src/grdview.py

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,12 @@
66
from typing import Literal
77

88
import xarray as xr
9+
from packaging.version import Version
910
from pygmt._typing import PathLike
1011
from pygmt.alias import Alias, AliasSystem
11-
from pygmt.clib import Session
12+
from pygmt.clib import Session, __gmt_version__
1213
from pygmt.helpers import build_arg_list, deprecate_parameter, fmt_docstring, use_alias
14+
from pygmt.src.grdinfo import grdinfo
1315

1416
__doctest_skip__ = ["grdview"]
1517

@@ -116,6 +118,8 @@ def grdview( # noqa: PLR0913
116118
value in the grid. However, if ``region`` was used to set *zmin/zmax* then
117119
*zmin* is used if it is less than the grid minimum value. Use ``facade_pen`` and
118120
``facade_fill`` to control the appearance of the plane.
121+
**Note**: For GMT<=6.6.0, *zmin* set in ``region`` has no effect due to a GMT
122+
bug.
119123
facade_fill
120124
Fill for the frontal facade between the plane specified by ``plane`` and the
121125
data perimeter.
@@ -174,6 +178,18 @@ def grdview( # noqa: PLR0913
174178
if plane is False and (facade_fill is not None or facade_pen is not None):
175179
plane = True
176180

181+
# Workaround for GMT bug https://github.com/GenericMappingTools/gmt/pull/8838
182+
# Fix the plane value to be the grid minimum if plane=True.
183+
# Notes:
184+
# 1. It's the minimum of the grid, not a subset of the grid defined by 'region'.
185+
# 2. The GMT docs says "if -R was used to set zmin/zmax then we use that value if
186+
# it is less than the grid minimum value.". We can't add a workaround for this
187+
# case since we can't parse zmin/zmax from 'region' if 'region' was set in
188+
# previous plotting commands.
189+
# TODO(GMT>6.6.0): Remove this workaround.
190+
if Version(__gmt_version__) <= Version("6.6.0") and plane is True:
191+
plane = grdinfo(grid, per_column=True).split()[4]
192+
177193
aliasdict = AliasSystem(
178194
Jz=Alias(zscale, name="zscale"),
179195
JZ=Alias(zsize, name="zsize"),
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
outs:
2-
- md5: cfff4879fbe7ab03d8a304b2622b9782
3-
size: 26208
2+
- md5: aa725f7d05462e7d272cf7045a7c9913
3+
size: 32037
44
hash: md5
55
path: test_grdview_facadepen_default_plane.png

0 commit comments

Comments
 (0)