Skip to content

Commit e9b4e5e

Browse files
authored
Figure.wiggle: Refactor the parameter fillpositive/fillnegative using the new alias system (#4041)
1 parent 1224c65 commit e9b4e5e

File tree

1 file changed

+32
-11
lines changed

1 file changed

+32
-11
lines changed

pygmt/src/wiggle.py

Lines changed: 32 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,37 @@
88
from pygmt.helpers import build_arg_list, fmt_docstring, kwargs_to_strings, use_alias
99

1010

11+
def _parse_fills(fillpositive, fillnegative):
12+
"""
13+
Parse the fillpositive and fillnegative parameters.
14+
15+
>>> _parse_fills("red", "blue")
16+
['red+p', 'blue+n']
17+
>>> _parse_fills(None, "blue")
18+
'blue+n'
19+
>>> _parse_fills("red", None)
20+
'red+p'
21+
>>> _parse_fills(None, None)
22+
"""
23+
_fills = []
24+
if fillpositive is not None:
25+
_fills.append(fillpositive + "+p")
26+
if fillnegative is not None:
27+
_fills.append(fillnegative + "+n")
28+
29+
match len(_fills):
30+
case 0:
31+
return None
32+
case 1:
33+
return _fills[0]
34+
case 2:
35+
return _fills
36+
37+
1138
@fmt_docstring
1239
@use_alias(
1340
B="frame",
1441
D="position",
15-
G="fillpositive/fillnegative-",
1642
R="region",
1743
T="track",
1844
V="verbose",
@@ -53,6 +79,7 @@ def wiggle(
5379
Full GMT docs at :gmt-docs:`wiggle.html`.
5480
5581
{aliases}
82+
- G = **+p**: fillpositive, **+n**: fillnegative
5683
- J = projection
5784
5885
Parameters
@@ -78,11 +105,9 @@ def wiggle(
78105
[**+o**\ *dx*\ [/*dy*]][**+l**\ [*label*]].
79106
Define the reference point on the map for the vertical scale bar.
80107
fillpositive : str
81-
Set color or pattern for filling positive wiggles
82-
[Default is no fill].
108+
Set color or pattern for filling positive wiggles [Default is no fill].
83109
fillnegative : str
84-
Set color or pattern for filling negative wiggles
85-
[Default is no fill].
110+
Set color or pattern for filling negative wiggles [Default is no fill].
86111
track : str
87112
Draw track [Default is no track]. Append pen attributes to use
88113
[Default is ``"0.25p,black,solid"``].
@@ -103,15 +128,11 @@ def wiggle(
103128
"""
104129
self._activate_figure()
105130

106-
if fillpositive or fillnegative:
107-
kwargs["G"] = []
108-
if fillpositive:
109-
kwargs["G"].append(fillpositive + "+p")
110-
if fillnegative:
111-
kwargs["G"].append(fillnegative + "+n")
131+
_fills = _parse_fills(fillpositive, fillnegative)
112132

113133
aliasdict = AliasSystem(
114134
J=Alias(projection, name="projection"),
135+
G=Alias(_fills, name="fillpositive/fillnegative"),
115136
).merge(kwargs)
116137

117138
with Session() as lib:

0 commit comments

Comments
 (0)