Skip to content
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

Figure.wiggle: Deprecate parameter "color" (remove in v0.12.0) and add "fillpositive"/"fillnegative" #2205

Merged
merged 19 commits into from
Dec 27, 2022
Merged
Show file tree
Hide file tree
Changes from 10 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
9 changes: 6 additions & 3 deletions examples/gallery/lines/wiggle.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
tracks. ``x``, ``y``, ``z`` can be specified as 1-D arrays or within a
specified file. The ``scale`` parameter can be used to set the scale of the
anomaly in data/distance units. The positive and/or negative areas can be
filled with color by setting the ``color`` parameter.
filled with color by setting the ``fill_positive`` and/or ``fill_negative``
parameters.
"""

import numpy as np
Expand All @@ -25,8 +26,10 @@
z=z,
# Set anomaly scale to 20 centimeters
scale="20c",
# Fill positive and negative areas red and gray, respectively
color=["red+p", "gray+n"],
# Fill positive areas red
fill_positive="red",
# Fill negative areas gray
fill_negative="gray",
# Set the outline width to 1.0 point
pen="1.0p",
# Draw a blue track with a width of 0.5 points
Expand Down
51 changes: 42 additions & 9 deletions pygmt/src/wiggle.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
"""
wiggle - Plot z=f(x,y) anomalies along tracks.
"""
import warnings

from pygmt.clib import Session
from pygmt.exceptions import GMTInvalidInput
from pygmt.helpers import build_arg_string, fmt_docstring, kwargs_to_strings, use_alias


Expand Down Expand Up @@ -30,7 +33,16 @@
w="wrap",
)
@kwargs_to_strings(R="sequence", c="sequence_comma", i="sequence_comma", p="sequence")
def wiggle(self, data=None, x=None, y=None, z=None, **kwargs):
def wiggle(
self,
data=None,
x=None,
y=None,
z=None,
fill_positive=None,
michaelgrund marked this conversation as resolved.
Show resolved Hide resolved
fill_negative=None,
**kwargs
):
r"""
Plot z=f(x,y) anomalies along tracks.

Expand Down Expand Up @@ -65,14 +77,12 @@ def wiggle(self, data=None, x=None, y=None, z=None, **kwargs):
**+w**\ *length*\ [**+j**\ *justify*]\ [**+al**\|\ **r**]\
[**+o**\ *dx*\ [/*dy*]][**+l**\ [*label*]].
Defines the reference point on the map for the vertical scale bar.
color : str
Set fill shade, color or pattern for positive and/or negative wiggles
[Default is no fill]. Optionally, append **+p** to fill positive areas
(this is the default behavior). Append **+n** to fill negative areas.
Append **+n+p** to fill both positive and negative areas with the same
fill. **Note**: You will need to repeat the color parameter to select
different fills for the positive and negative wiggles.

fill_positive : str
Set fill shade, color or pattern for positive wiggles [Default is no
fill].
fill_negative : str
Set fill shade, color or pattern for 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 @@ -94,6 +104,29 @@ def wiggle(self, data=None, x=None, y=None, z=None, **kwargs):
"""
kwargs = self._preprocess(**kwargs) # pylint: disable=protected-access

if kwargs.get("G") is not None:
michaelgrund marked this conversation as resolved.
Show resolved Hide resolved
msg = (
"The 'color' parameter has been deprecated since v0.8.0"
" and will be removed in v0.12.0. Use fill_positive/fill_negative"
" instead."
)
warnings.warn(msg, category=FutureWarning, stacklevel=2)

if (fill_positive or fill_negative) and kwargs.get("G") is not None:
raise GMTInvalidInput("Use either fill_positive/fill_negative or color.")

if fill_positive:
if kwargs.get("G") is not None:
kwargs["G"] = [kwargs["G"], fill_positive + "+p"]
michaelgrund marked this conversation as resolved.
Show resolved Hide resolved
else:
kwargs["G"] = fill_positive + "+p"

if fill_negative:
if kwargs.get("G") is not None:
kwargs["G"] = [kwargs["G"], fill_negative + "+n"]
else:
kwargs["G"] = fill_negative + "+n"

with Session() as lib:
# Choose how data will be passed in to the module
file_context = lib.virtualfile_from_data(
Expand Down
6 changes: 4 additions & 2 deletions pygmt/tests/test_wiggle.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ def test_wiggle():
y=y,
z=z,
scale="0.5c",
color=["red+p", "gray+n"],
fill_positive="red",
fill_negative="gray",
pen="1.0p",
track="0.5p",
position="jRM+w2+lnT",
Expand Down Expand Up @@ -51,7 +52,8 @@ def test_wiggle_data_incols():
projection="X8c",
incols=[1, 0, 2],
scale="0.5c",
color=["red+p", "gray+n"],
fill_positive="red",
fill_negative="gray",
pen="1.0p",
track="0.5p",
position="jRM+w2+lnT",
Expand Down