From b666bda4a4082f73e7d1e2d5c08b831eba4b9569 Mon Sep 17 00:00:00 2001 From: Dongdong Tian Date: Thu, 23 Oct 2025 17:15:05 +0800 Subject: [PATCH 1/6] Figure.subplot: Migrate the 'margins' parameter to the new alias system --- pygmt/src/subplot.py | 34 ++++++++++++++++++---------------- 1 file changed, 18 insertions(+), 16 deletions(-) diff --git a/pygmt/src/subplot.py b/pygmt/src/subplot.py index 4a099f2015a..f133f54109b 100644 --- a/pygmt/src/subplot.py +++ b/pygmt/src/subplot.py @@ -6,7 +6,7 @@ from collections.abc import Sequence from typing import Literal -from pygmt.alias import AliasSystem +from pygmt.alias import Alias, AliasSystem from pygmt.clib import Session from pygmt.exceptions import GMTInvalidInput, GMTValueError from pygmt.helpers import ( @@ -25,16 +25,16 @@ A="autolabel", B="frame", C="clearance", - M="margins", SC="sharex", SR="sharey", T="title", ) -@kwargs_to_strings(Ff="sequence", Fs="sequence", M="sequence") +@kwargs_to_strings(Ff="sequence", Fs="sequence") def subplot( self, nrows=1, ncols=1, + margins: float | str | Sequence[float | str] | None = None, projection: str | None = None, region: Sequence[float | str] | str | None = None, verbose: Literal["quiet", "error", "warning", "timing", "info", "compat", "debug"] @@ -54,6 +54,7 @@ def subplot( {aliases} - J = projection + - M = margins - R = region - V = verbose @@ -108,21 +109,20 @@ def subplot( the main map plotting but can be accessed by methods that plot scales, bars, text, etc. {projection} - margins : str or list - This is margin space that is added between neighboring subplots (i.e., - the interior margins) in addition to the automatic space added for tick - marks, annotations, and labels. The margins can be specified as either: + margins + This is margin space that is added between neighboring subplots (i.e., the + interior margins) in addition to the automatic space added for tick marks, + annotations, and labels. The margins can be specified as either: - a single value (for same margin on all sides). E.g. ``"5c"``. - - a pair of values (for setting separate horizontal and vertical - margins). E.g. ``["5c", "3c"]``. - - a set of four values (for setting separate left, right, bottom, and - top margins). E.g. ``["1c", "2c", "3c", "4c"]``. + - a pair of values (for setting separate horizontal and vertical margins). E.g., + ``("5c", "3c")``. + - a set of four values (for setting separate left, right, bottom, and top + margins). E.g., ``("1c", "2c", "3c", "4c")``. - The actual gap created is always a sum of the margins for the two - opposing sides (e.g., east plus west or south plus north margins) - [Default is half the primary annotation font size, giving the full - annotation font size as the default gap]. + The actual gap created is always a sum of the margins for the two opposing sides + (e.g., east plus west or south plus north margins) [Default is half the primary + annotation font size, giving the full annotation font size as the default gap]. {region} sharex : bool or str Set subplot layout for shared x-axes. Use when all subplots in a column @@ -172,7 +172,9 @@ def subplot( msg = "Please provide either one of 'figsize' or 'subsize' only." raise GMTInvalidInput(msg) - aliasdict = AliasSystem().add_common( + aliasdict = AliasSystem( + M=Alias(margins, name="margins", sep="/", size=(2, 4)), + ).add_common( J=projection, R=region, V=verbose, From f5c6345e50ba7544dc83f698c4ddf980bc544d82 Mon Sep 17 00:00:00 2001 From: Dongdong Tian Date: Thu, 6 Nov 2025 18:46:15 +0800 Subject: [PATCH 2/6] Apply suggestion from @yvonnefroehlich 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/subplot.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/pygmt/src/subplot.py b/pygmt/src/subplot.py index f133f54109b..0858b9fe550 100644 --- a/pygmt/src/subplot.py +++ b/pygmt/src/subplot.py @@ -112,6 +112,8 @@ def subplot( margins This is margin space that is added between neighboring subplots (i.e., the interior margins) in addition to the automatic space added for tick marks, + Margin space that is added between neighboring subplots (i.e., the + interior margins) in addition to the automatic space added for tick marks, annotations, and labels. The margins can be specified as either: - a single value (for same margin on all sides). E.g. ``"5c"``. From 6c84dd13444e27c007ed8dda3c2e5c6669ef4dbb Mon Sep 17 00:00:00 2001 From: Dongdong Tian Date: Thu, 6 Nov 2025 18:47:32 +0800 Subject: [PATCH 3/6] Rewrap --- pygmt/src/subplot.py | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/pygmt/src/subplot.py b/pygmt/src/subplot.py index 0858b9fe550..3c5b074f63e 100644 --- a/pygmt/src/subplot.py +++ b/pygmt/src/subplot.py @@ -110,11 +110,9 @@ def subplot( scales, bars, text, etc. {projection} margins - This is margin space that is added between neighboring subplots (i.e., the - interior margins) in addition to the automatic space added for tick marks, - Margin space that is added between neighboring subplots (i.e., the - interior margins) in addition to the automatic space added for tick marks, - annotations, and labels. The margins can be specified as either: + Margin space that is added between neighboring subplots (i.e., the interior + margins) in addition to the automatic space added for tick marks, annotations, + and labels. The margins can be specified as either: - a single value (for same margin on all sides). E.g. ``"5c"``. - a pair of values (for setting separate horizontal and vertical margins). E.g., From 2b0d90c1977b47e969f46e6e7763d5f5f94058ff Mon Sep 17 00:00:00 2001 From: Dongdong Tian Date: Fri, 7 Nov 2025 00:34:18 +0800 Subject: [PATCH 4/6] Update pygmt/src/subplot.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/subplot.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pygmt/src/subplot.py b/pygmt/src/subplot.py index 3c5b074f63e..5ff1348b0e8 100644 --- a/pygmt/src/subplot.py +++ b/pygmt/src/subplot.py @@ -115,10 +115,10 @@ def subplot( and labels. The margins can be specified as either: - a single value (for same margin on all sides). E.g. ``"5c"``. - - a pair of values (for setting separate horizontal and vertical margins). E.g., + - a pair of values (for separate horizontal and vertical margins). E.g., ``("5c", "3c")``. - - a set of four values (for setting separate left, right, bottom, and top - margins). E.g., ``("1c", "2c", "3c", "4c")``. + - a set of four values (for separate left, right, bottom, and top margins). E.g., + ``("1c", "2c", "3c", "4c")``. The actual gap created is always a sum of the margins for the two opposing sides (e.g., east plus west or south plus north margins) [Default is half the primary From 16b9e781b29a85b7c9d90653eead1845fa2f8156 Mon Sep 17 00:00:00 2001 From: Dongdong Tian Date: Fri, 7 Nov 2025 10:20:42 +0800 Subject: [PATCH 5/6] Fix style [skip ci] --- pygmt/src/subplot.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pygmt/src/subplot.py b/pygmt/src/subplot.py index 5ff1348b0e8..ceb31942006 100644 --- a/pygmt/src/subplot.py +++ b/pygmt/src/subplot.py @@ -117,8 +117,8 @@ def subplot( - a single value (for same margin on all sides). E.g. ``"5c"``. - a pair of values (for separate horizontal and vertical margins). E.g., ``("5c", "3c")``. - - a set of four values (for separate left, right, bottom, and top margins). E.g., - ``("1c", "2c", "3c", "4c")``. + - a set of four values (for separate left, right, bottom, and top margins). + E.g., ``("1c", "2c", "3c", "4c")``. The actual gap created is always a sum of the margins for the two opposing sides (e.g., east plus west or south plus north margins) [Default is half the primary From 900260c66d4555cfdb4f9f5e80f3e21bb7080983 Mon Sep 17 00:00:00 2001 From: Dongdong Tian Date: Fri, 7 Nov 2025 10:22:50 +0800 Subject: [PATCH 6/6] Fix style [skip ci] --- pygmt/src/subplot.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pygmt/src/subplot.py b/pygmt/src/subplot.py index ceb31942006..bf91cf877fc 100644 --- a/pygmt/src/subplot.py +++ b/pygmt/src/subplot.py @@ -117,7 +117,7 @@ def subplot( - a single value (for same margin on all sides). E.g. ``"5c"``. - a pair of values (for separate horizontal and vertical margins). E.g., ``("5c", "3c")``. - - a set of four values (for separate left, right, bottom, and top margins). + - a set of four values (for separate left, right, bottom, and top margins). E.g., ``("1c", "2c", "3c", "4c")``. The actual gap created is always a sum of the margins for the two opposing sides