diff --git a/pygmt/src/grdview.py b/pygmt/src/grdview.py index 0ce5ddbf673..ebf820508fb 100644 --- a/pygmt/src/grdview.py +++ b/pygmt/src/grdview.py @@ -6,10 +6,12 @@ from typing import Literal import xarray as xr +from packaging.version import Version from pygmt._typing import PathLike from pygmt.alias import Alias, AliasSystem -from pygmt.clib import Session +from pygmt.clib import Session, __gmt_version__ from pygmt.helpers import build_arg_list, deprecate_parameter, fmt_docstring, use_alias +from pygmt.src.grdinfo import grdinfo __doctest_skip__ = ["grdview"] @@ -116,6 +118,8 @@ def grdview( # noqa: PLR0913 value in the grid. However, if ``region`` was used to set *zmin/zmax* then *zmin* is used if it is less than the grid minimum value. Use ``facade_pen`` and ``facade_fill`` to control the appearance of the plane. + **Note**: For GMT<=6.6.0, *zmin* set in ``region`` has no effect due to a GMT + bug. facade_fill Fill for the frontal facade between the plane specified by ``plane`` and the data perimeter. @@ -174,6 +178,18 @@ def grdview( # noqa: PLR0913 if plane is False and (facade_fill is not None or facade_pen is not None): plane = True + # Workaround for GMT bug https://github.com/GenericMappingTools/gmt/pull/8838 + # Fix the plane value to be the grid minimum if plane=True. + # Notes: + # 1. It's the minimum of the grid, not a subset of the grid defined by 'region'. + # 2. The GMT docs says "if -R was used to set zmin/zmax then we use that value if + # it is less than the grid minimum value.". We can't add a workaround for this + # case since we can't parse zmin/zmax from 'region' if 'region' was set in + # previous plotting commands. + # TODO(GMT>6.6.0): Remove this workaround. + if Version(__gmt_version__) <= Version("6.6.0") and plane is True: + plane = grdinfo(grid, per_column=True).split()[4] + aliasdict = AliasSystem( Jz=Alias(zscale, name="zscale"), JZ=Alias(zsize, name="zsize"), diff --git a/pygmt/tests/baseline/test_grdview_facadepen_default_plane.png.dvc b/pygmt/tests/baseline/test_grdview_facadepen_default_plane.png.dvc index 5e56c5a43d7..b14d4713cb7 100644 --- a/pygmt/tests/baseline/test_grdview_facadepen_default_plane.png.dvc +++ b/pygmt/tests/baseline/test_grdview_facadepen_default_plane.png.dvc @@ -1,5 +1,5 @@ outs: -- md5: cfff4879fbe7ab03d8a304b2622b9782 - size: 26208 +- md5: aa725f7d05462e7d272cf7045a7c9913 + size: 32037 hash: md5 path: test_grdview_facadepen_default_plane.png