Skip to content

Commit 25fab2e

Browse files
michaelgrundseismanyvonnefroehlich
authored
Figure.wiggle: Deprecate parameter "color" (remove in v0.12.0) and add "fillpositive"/"fillnegative" (#2205)
Co-authored-by: Dongdong Tian <[email protected]> Co-authored-by: Yvonne Fröhlich <[email protected]>
1 parent a1e50ac commit 25fab2e

File tree

3 files changed

+103
-14
lines changed

3 files changed

+103
-14
lines changed

examples/gallery/lines/wiggle.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66
tracks. ``x``, ``y``, ``z`` can be specified as 1-D arrays or within a
77
specified file. The ``scale`` parameter can be used to set the scale of the
88
anomaly in data/distance units. The positive and/or negative areas can be
9-
filled with color by setting the ``color`` parameter.
9+
filled with color by setting the ``fillpositive`` and/or ``fillnegative``
10+
parameters.
1011
"""
1112

1213
import numpy as np
@@ -25,8 +26,10 @@
2526
z=z,
2627
# Set anomaly scale to 20 centimeters
2728
scale="20c",
28-
# Fill positive and negative areas red and gray, respectively
29-
color=["red+p", "gray+n"],
29+
# Fill positive areas red
30+
fillpositive="red",
31+
# Fill negative areas gray
32+
fillnegative="gray",
3033
# Set the outline width to 1.0 point
3134
pen="1.0p",
3235
# Draw a blue track with a width of 0.5 points

pygmt/src/wiggle.py

Lines changed: 37 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
"""
22
wiggle - Plot z=f(x,y) anomalies along tracks.
33
"""
4+
import warnings
5+
46
from pygmt.clib import Session
7+
from pygmt.exceptions import GMTInvalidInput
58
from pygmt.helpers import build_arg_string, fmt_docstring, kwargs_to_strings, use_alias
69

710

@@ -30,7 +33,16 @@
3033
w="wrap",
3134
)
3235
@kwargs_to_strings(R="sequence", c="sequence_comma", i="sequence_comma", p="sequence")
33-
def wiggle(self, data=None, x=None, y=None, z=None, **kwargs):
36+
def wiggle(
37+
self,
38+
data=None,
39+
x=None,
40+
y=None,
41+
z=None,
42+
fillpositive=None,
43+
fillnegative=None,
44+
**kwargs
45+
):
3446
r"""
3547
Plot z=f(x,y) anomalies along tracks.
3648
@@ -65,14 +77,12 @@ def wiggle(self, data=None, x=None, y=None, z=None, **kwargs):
6577
**+w**\ *length*\ [**+j**\ *justify*]\ [**+al**\|\ **r**]\
6678
[**+o**\ *dx*\ [/*dy*]][**+l**\ [*label*]].
6779
Defines the reference point on the map for the vertical scale bar.
68-
color : str
69-
Set fill shade, color or pattern for positive and/or negative wiggles
70-
[Default is no fill]. Optionally, append **+p** to fill positive areas
71-
(this is the default behavior). Append **+n** to fill negative areas.
72-
Append **+n+p** to fill both positive and negative areas with the same
73-
fill. **Note**: You will need to repeat the color parameter to select
74-
different fills for the positive and negative wiggles.
75-
80+
fillpositive : str
81+
Set fill shade, color, or pattern for positive wiggles [Default is no
82+
fill].
83+
fillnegative : str
84+
Set fill shade, color, or pattern for negative wiggles [Default is no
85+
fill].
7686
track : str
7787
Draw track [Default is no track]. Append pen attributes to use
7888
[Default is ``"0.25p,black,solid"``].
@@ -94,6 +104,24 @@ def wiggle(self, data=None, x=None, y=None, z=None, **kwargs):
94104
"""
95105
kwargs = self._preprocess(**kwargs) # pylint: disable=protected-access
96106

107+
if (fillpositive or fillnegative) and kwargs.get("G") is not None:
108+
raise GMTInvalidInput("Use either fillpositive/fillnegative or color.")
109+
110+
if kwargs.get("G") is not None:
111+
msg = (
112+
"The 'color' parameter has been deprecated since v0.8.0"
113+
" and will be removed in v0.12.0. Use fillpositive/fillnegative"
114+
" instead."
115+
)
116+
warnings.warn(msg, category=FutureWarning, stacklevel=2)
117+
118+
if fillpositive or fillnegative:
119+
kwargs["G"] = []
120+
if fillpositive:
121+
kwargs["G"].append(fillpositive + "+p")
122+
if fillnegative:
123+
kwargs["G"].append(fillnegative + "+n")
124+
97125
with Session() as lib:
98126
# Choose how data will be passed in to the module
99127
file_context = lib.virtualfile_from_data(

pygmt/tests/test_wiggle.py

Lines changed: 60 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import numpy as np
55
import pytest
66
from pygmt import Figure
7+
from pygmt.exceptions import GMTInvalidInput
78

89

910
@pytest.mark.mpl_image_compare
@@ -23,7 +24,8 @@ def test_wiggle():
2324
y=y,
2425
z=z,
2526
scale="0.5c",
26-
color=["red+p", "gray+n"],
27+
fillpositive="red",
28+
fillnegative="gray",
2729
pen="1.0p",
2830
track="0.5p",
2931
position="jRM+w2+lnT",
@@ -51,9 +53,65 @@ def test_wiggle_data_incols():
5153
projection="X8c",
5254
incols=[1, 0, 2],
5355
scale="0.5c",
54-
color=["red+p", "gray+n"],
56+
fillpositive="red",
57+
fillnegative="gray",
5558
pen="1.0p",
5659
track="0.5p",
5760
position="jRM+w2+lnT",
5861
)
5962
return fig
63+
64+
65+
def test_wiggle_fill_multiple():
66+
"""
67+
Check that wiggle fails when the parameters color and
68+
fillpositive/fillnegative are used together.
69+
"""
70+
x = np.arange(-2, 2, 0.02)
71+
y = np.zeros(x.size)
72+
z = np.cos(2 * np.pi * x)
73+
74+
fig = Figure()
75+
with pytest.raises(GMTInvalidInput):
76+
fig.wiggle(
77+
x=x,
78+
y=y,
79+
z=z,
80+
region=[-4, 4, -1, 1],
81+
projection="X8c",
82+
incols=[1, 0, 2],
83+
scale="0.5c",
84+
color="blue",
85+
fillpositive="red",
86+
fillnegative="gray",
87+
pen="1.0p",
88+
track="0.5p",
89+
position="jRM+w2+lnT",
90+
)
91+
92+
93+
def test_wiggle_use_color():
94+
"""
95+
Check that wiggle raises a warning when the deprecated parameter color is
96+
used.
97+
"""
98+
x = np.arange(-2, 2, 0.02)
99+
y = np.zeros(x.size)
100+
z = np.cos(2 * np.pi * x)
101+
102+
fig = Figure()
103+
with pytest.warns(expected_warning=FutureWarning) as record:
104+
fig.wiggle(
105+
x=x,
106+
y=y,
107+
z=z,
108+
region=[-4, 4, -1, 1],
109+
projection="X8c",
110+
incols=[1, 0, 2],
111+
scale="0.5c",
112+
color="blue",
113+
pen="1.0p",
114+
track="0.5p",
115+
position="jRM+w2+lnT",
116+
)
117+
assert len(record) == 1

0 commit comments

Comments
 (0)