From 16cf2c30f209c65c5537cd9898c1397740cddb8b Mon Sep 17 00:00:00 2001 From: Dongdong Tian Date: Mon, 15 Dec 2025 19:48:31 +0800 Subject: [PATCH 1/5] Figure.grdview: Fix the default z-plane to the grid z minimum when plane is set to True or facede_fill/facede_pen is set. --- pygmt/src/grdview.py | 18 +++++++++++++++--- ...est_grdview_facadepen_default_plane.png.dvc | 4 ++-- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/pygmt/src/grdview.py b/pygmt/src/grdview.py index 0ce5ddbf673..da2adfb1fdb 100644 --- a/pygmt/src/grdview.py +++ b/pygmt/src/grdview.py @@ -10,6 +10,7 @@ from pygmt.alias import Alias, AliasSystem from pygmt.clib import Session from pygmt.helpers import build_arg_list, deprecate_parameter, fmt_docstring, use_alias +from pygmt.src.grdinfo import grdinfo __doctest_skip__ = ["grdview"] @@ -113,9 +114,8 @@ def grdview( # noqa: PLR0913 **m** or **sm** for meshlines to be drawn. plane Draw a plane at the specified z-level. If ``True``, defaults to the minimum - 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. + value in the grid. Use ``facade_pen`` and ``facade_fill`` to control the + appearance of the plane. facade_fill Fill for the frontal facade between the plane specified by ``plane`` and the data perimeter. @@ -174,6 +174,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 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 From 3b60b9de2ea12cd71e9429a245ae400d5170d23e Mon Sep 17 00:00:00 2001 From: Dongdong Tian Date: Mon, 15 Dec 2025 19:52:31 +0800 Subject: [PATCH 2/5] Check GMT version --- pygmt/src/grdview.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/pygmt/src/grdview.py b/pygmt/src/grdview.py index da2adfb1fdb..733746fb7f6 100644 --- a/pygmt/src/grdview.py +++ b/pygmt/src/grdview.py @@ -6,9 +6,10 @@ 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 @@ -183,7 +184,7 @@ def grdview( # noqa: PLR0913 # 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 plane is True: + if Version(__gmt_version__) <= Version("6.6.0") and plane is True: plane = grdinfo(grid, per_column=True).split()[4] aliasdict = AliasSystem( From 604f713b7d2914e0e20061cef322586db0f1f7d1 Mon Sep 17 00:00:00 2001 From: Dongdong Tian Date: Mon, 15 Dec 2025 20:00:07 +0800 Subject: [PATCH 3/5] Add a note about upstream bug --- pygmt/src/grdview.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/pygmt/src/grdview.py b/pygmt/src/grdview.py index 733746fb7f6..01a7d75fc0d 100644 --- a/pygmt/src/grdview.py +++ b/pygmt/src/grdview.py @@ -115,8 +115,11 @@ def grdview( # noqa: PLR0913 **m** or **sm** for meshlines to be drawn. plane Draw a plane at the specified z-level. If ``True``, defaults to the minimum - value in the grid. Use ``facade_pen`` and ``facade_fill`` to control the - appearance of the plane. + 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. From 8d09f670035918d695e09bc629bffe9124f0931c Mon Sep 17 00:00:00 2001 From: Dongdong Tian Date: Tue, 16 Dec 2025 05:49:11 +0800 Subject: [PATCH 4/5] Update pygmt/src/grdview.py MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Yvonne Fröhlich <94163266+yvonnefroehlich@users.noreply.github.com> --- pygmt/src/grdview.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pygmt/src/grdview.py b/pygmt/src/grdview.py index 01a7d75fc0d..32c92d54cc7 100644 --- a/pygmt/src/grdview.py +++ b/pygmt/src/grdview.py @@ -181,7 +181,7 @@ def grdview( # noqa: PLR0913 # 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'. + # 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 From 567415a4f7853295aab7c5eec2e641dd63832e08 Mon Sep 17 00:00:00 2001 From: Dongdong Tian Date: Tue, 16 Dec 2025 05:49:18 +0800 Subject: [PATCH 5/5] Update pygmt/src/grdview.py MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Yvonne Fröhlich <94163266+yvonnefroehlich@users.noreply.github.com> --- pygmt/src/grdview.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pygmt/src/grdview.py b/pygmt/src/grdview.py index 32c92d54cc7..ebf820508fb 100644 --- a/pygmt/src/grdview.py +++ b/pygmt/src/grdview.py @@ -184,7 +184,7 @@ def grdview( # noqa: PLR0913 # 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 + # 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: