Skip to content

Commit c635ae8

Browse files
committed
Figure.wiggle: Refactor the parameter fillpositive/fillnegative using the new alias system
1 parent b5eff49 commit c635ae8

File tree

1 file changed

+25
-11
lines changed

1 file changed

+25
-11
lines changed

pygmt/src/wiggle.py

Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,30 @@
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:
25+
_fills.append(fillpositive + "+p")
26+
if fillnegative:
27+
_fills.append(fillnegative + "+n")
28+
return _fills or None
29+
30+
1131
@fmt_docstring
1232
@use_alias(
1333
B="frame",
1434
D="position",
15-
G="fillpositive/fillnegative-",
1635
R="region",
1736
T="track",
1837
V="verbose",
@@ -54,6 +73,7 @@ def wiggle(
5473
5574
{aliases}
5675
- J=projection
76+
- G=**+p**: fillpositive, **+n**: fillnegative
5777
5878
Parameters
5979
----------
@@ -78,11 +98,9 @@ def wiggle(
7898
[**+o**\ *dx*\ [/*dy*]][**+l**\ [*label*]].
7999
Define the reference point on the map for the vertical scale bar.
80100
fillpositive : str
81-
Set color or pattern for filling positive wiggles
82-
[Default is no fill].
101+
Set color or pattern for filling positive wiggles [Default is no fill].
83102
fillnegative : str
84-
Set color or pattern for filling negative wiggles
85-
[Default is no fill].
103+
Set color or pattern for filling negative wiggles [Default is no fill].
86104
track : str
87105
Draw track [Default is no track]. Append pen attributes to use
88106
[Default is ``"0.25p,black,solid"``].
@@ -103,15 +121,11 @@ def wiggle(
103121
"""
104122
self._activate_figure()
105123

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")
124+
_fills = _parse_fills(fillpositive, fillnegative)
112125

113126
aliasdict = AliasSystem(
114127
J=Alias(projection, name="projection"),
128+
G=Alias(_fills, name="fillpositive/fillnegative"),
115129
).merge(kwargs)
116130

117131
with Session() as lib:

0 commit comments

Comments
 (0)