Skip to content

Figure.wiggle: Refactor the parameter fillpositive/fillnegative using the new alias system #4041

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 32 additions & 11 deletions pygmt/src/wiggle.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,37 @@
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 is not None:
_fills.append(fillpositive + "+p")
if fillnegative is not None:
_fills.append(fillnegative + "+n")

match len(_fills):
case 0:
return None
case 1:
return _fills[0]
case 2:
return _fills


@fmt_docstring
@use_alias(
B="frame",
D="position",
G="fillpositive/fillnegative-",
R="region",
T="track",
V="verbose",
Expand Down Expand Up @@ -53,6 +79,7 @@ def wiggle(
Full GMT docs at :gmt-docs:`wiggle.html`.

{aliases}
- G = **+p**: fillpositive, **+n**: fillnegative
- J = projection

Parameters
Expand All @@ -78,11 +105,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"``].
Expand All @@ -103,15 +128,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:
Expand Down
Loading