From 6febfb1998d8df0d480a62bad6c9bef480ea9e65 Mon Sep 17 00:00:00 2001 From: Dongdong Tian Date: Sun, 10 Aug 2025 18:40:46 +0800 Subject: [PATCH 1/2] Figure.wiggle: Refactor the parameter fillpositive/fillnegative using the new alias system --- pygmt/src/wiggle.py | 38 ++++++++++++++++++++++++++------------ 1 file changed, 26 insertions(+), 12 deletions(-) diff --git a/pygmt/src/wiggle.py b/pygmt/src/wiggle.py index e4885809680..8814159ca08 100644 --- a/pygmt/src/wiggle.py +++ b/pygmt/src/wiggle.py @@ -8,11 +8,30 @@ from pygmt.helpers import build_arg_list, fmt_docstring, kwargs_to_strings, use_alias +def _parse_fills(fillpositive, fillnegative): + """ + Parse the fillpositive and fillnegative parameters. + + >>> _parse_fills("red", "blue") + ['red+p', 'blue+n'] + >>> _parse_fills(None, "blue") + ['blue+n'] + >>> _parse_fills("red", None) + ['red+p'] + >>> _parse_fills(None, None) + """ + _fills = [] + if fillpositive: + _fills.append(fillpositive + "+p") + if fillnegative: + _fills.append(fillnegative + "+n") + return _fills or None + + @fmt_docstring @use_alias( B="frame", D="position", - G="fillpositive/fillnegative-", R="region", T="track", V="verbose", @@ -53,7 +72,8 @@ def wiggle( Full GMT docs at :gmt-docs:`wiggle.html`. {aliases} - - J=projection + - G = **+p**: fillpositive, **+n**: fillnegative + - J = projection Parameters ---------- @@ -78,11 +98,9 @@ def wiggle( [**+o**\ *dx*\ [/*dy*]][**+l**\ [*label*]]. Define the reference point on the map for the vertical scale bar. fillpositive : str - Set color or pattern for filling positive wiggles - [Default is no fill]. + Set color or pattern for filling positive wiggles [Default is no fill]. fillnegative : str - Set color or pattern for filling negative wiggles - [Default is no fill]. + Set color or pattern for filling negative wiggles [Default is no fill]. track : str Draw track [Default is no track]. Append pen attributes to use [Default is ``"0.25p,black,solid"``]. @@ -103,15 +121,11 @@ def wiggle( """ self._activate_figure() - if fillpositive or fillnegative: - kwargs["G"] = [] - if fillpositive: - kwargs["G"].append(fillpositive + "+p") - if fillnegative: - kwargs["G"].append(fillnegative + "+n") + _fills = _parse_fills(fillpositive, fillnegative) aliasdict = AliasSystem( J=Alias(projection, name="projection"), + G=Alias(_fills, name="fillpositive/fillnegative"), ).merge(kwargs) with Session() as lib: From 6f7f9d92ad21064fec78d2391835dbf54da5d421 Mon Sep 17 00:00:00 2001 From: Dongdong Tian Date: Mon, 11 Aug 2025 14:47:54 +0800 Subject: [PATCH 2/2] Update _parse_fills --- pygmt/src/wiggle.py | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/pygmt/src/wiggle.py b/pygmt/src/wiggle.py index 8814159ca08..97731ec1f6d 100644 --- a/pygmt/src/wiggle.py +++ b/pygmt/src/wiggle.py @@ -15,17 +15,24 @@ def _parse_fills(fillpositive, fillnegative): >>> _parse_fills("red", "blue") ['red+p', 'blue+n'] >>> _parse_fills(None, "blue") - ['blue+n'] + 'blue+n' >>> _parse_fills("red", None) - ['red+p'] + 'red+p' >>> _parse_fills(None, None) """ _fills = [] - if fillpositive: + if fillpositive is not None: _fills.append(fillpositive + "+p") - if fillnegative: + if fillnegative is not None: _fills.append(fillnegative + "+n") - return _fills or None + + match len(_fills): + case 0: + return None + case 1: + return _fills[0] + case 2: + return _fills @fmt_docstring