Skip to content

Commit 4777a6f

Browse files
seismanmichaelgrundweiji14
authored
Figure.plot3d: Deprecate parameter "sizes" to "size" (remove in v0.6.0) (#1258)
* Rename 'sizes' to 'size' * Updates tests and examples to use the new parameter name * Use the deprecate_parameter decorator for backward-compatibility * Add a test for checking 'sizes' backward compatibility Co-authored-by: Michael Grund <[email protected]> Co-authored-by: Wei Ji <[email protected]>
1 parent 53b4e74 commit 4777a6f

File tree

3 files changed

+42
-13
lines changed

3 files changed

+42
-13
lines changed

examples/gallery/3d_plots/scatter3d.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@
4747
y=df.sepal_length,
4848
z=df.petal_length,
4949
# Vary each symbol size according to another feature (sepal width, scaled by 0.1)
50-
sizes=0.1 * df.sepal_width,
50+
size=0.1 * df.sepal_width,
5151
# Use 3D cubes ("u") as symbols, with size in centimeter units ("c")
5252
style="uc",
5353
# Points colored by categorical number code

pygmt/src/plot3d.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
from pygmt.helpers import (
77
build_arg_string,
88
data_kind,
9+
deprecate_parameter,
910
fmt_docstring,
1011
is_nonstr_iter,
1112
kwargs_to_strings,
@@ -43,8 +44,9 @@
4344
t="transparency",
4445
)
4546
@kwargs_to_strings(R="sequence", c="sequence_comma", i="sequence_comma", p="sequence")
47+
@deprecate_parameter("sizes", "size", "v0.4.0", remove_version="v0.6.0")
4648
def plot3d(
47-
self, x=None, y=None, z=None, data=None, sizes=None, direction=None, **kwargs
49+
self, x=None, y=None, z=None, data=None, size=None, direction=None, **kwargs
4850
):
4951
r"""
5052
Plot lines, polygons, and symbols in 3-D.
@@ -80,8 +82,8 @@ def plot3d(
8082
Either a data file name or a 2d numpy array with the tabular data.
8183
Use parameter ``columns`` to choose which columns are x, y, z,
8284
color, and size, respectively.
83-
sizes : 1d array
84-
The sizes of the data points in units specified in ``style``.
85+
size : 1d array
86+
The size of the data points in units specified in ``style``.
8587
Only valid if using ``x``/``y``/``z``.
8688
direction : list of two 1d arrays
8789
If plotting vectors (using ``style='V'`` or ``style='v'``), then
@@ -179,12 +181,12 @@ def plot3d(
179181
)
180182
extra_arrays.append(kwargs["G"])
181183
del kwargs["G"]
182-
if sizes is not None:
184+
if size is not None:
183185
if kind != "vectors":
184186
raise GMTInvalidInput(
185-
"Can't use arrays for sizes if data is matrix or file."
187+
"Can't use arrays for 'size' if data is a matrix or a file."
186188
)
187-
extra_arrays.append(sizes)
189+
extra_arrays.append(size)
188190

189191
for flag in ["I", "t"]:
190192
if flag in kwargs and is_nonstr_iter(kwargs[flag]):

pygmt/tests/test_plot3d.py

Lines changed: 33 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -110,15 +110,15 @@ def test_plot3d_fail_no_data(data, region):
110110

111111
def test_plot3d_fail_color_size_intensity(data, region):
112112
"""
113-
Should raise an exception if array color, sizes and intensity are used with
113+
Should raise an exception if array color, size and intensity are used with
114114
matrix.
115115
"""
116116
fig = Figure()
117117
kwargs = dict(data=data, region=region, projection="X10c", frame="afg")
118118
with pytest.raises(GMTInvalidInput):
119119
fig.plot3d(style="c0.2c", color=data[:, 2], **kwargs)
120120
with pytest.raises(GMTInvalidInput):
121-
fig.plot3d(style="cc", sizes=data[:, 2], color="red", **kwargs)
121+
fig.plot3d(style="cc", size=data[:, 2], color="red", **kwargs)
122122
with pytest.raises(GMTInvalidInput):
123123
fig.plot3d(style="cc", intensity=data[:, 2], color="red", **kwargs)
124124

@@ -178,7 +178,7 @@ def test_plot3d_sizes(data, region):
178178
z=data[:, 2],
179179
zscale=5,
180180
perspective=[225, 30],
181-
sizes=0.5 * data[:, 2],
181+
size=0.5 * data[:, 2],
182182
region=region,
183183
projection="X10c",
184184
# Using inches instead of cm because of upstream bug at
@@ -203,7 +203,7 @@ def test_plot3d_colors_sizes(data, region):
203203
zscale=5,
204204
perspective=[225, 30],
205205
color=data[:, 2],
206-
sizes=0.5 * data[:, 2],
206+
size=0.5 * data[:, 2],
207207
region=region,
208208
projection="X6c",
209209
# Using inches instead of cm because of upstream bug at
@@ -231,7 +231,7 @@ def test_plot3d_colors_sizes_proj(data, region):
231231
projection="M20c",
232232
frame=["af", "zaf"],
233233
color=data[:, 2],
234-
sizes=data[:, 2],
234+
size=data[:, 2],
235235
# Using inches instead of cm because of upstream bug at
236236
# https://github.com/GenericMappingTools/gmt/issues/4386
237237
style="ui",
@@ -343,7 +343,7 @@ def test_plot3d_sizes_colors_transparencies():
343343
frame=True,
344344
style="uc",
345345
color=color,
346-
sizes=size,
346+
size=size,
347347
cmap="gray",
348348
transparency=transparency,
349349
)
@@ -458,3 +458,30 @@ def test_plot3d_scalar_xyz():
458458
x=1.5, y=-1.5, z=1.5, style="s1c", color="blue", zscale=True, perspective=True
459459
)
460460
return fig
461+
462+
463+
@pytest.mark.mpl_image_compare(filename="test_plot3d_sizes.png")
464+
def test_plot3d_deprecate_sizes_to_size(data, region):
465+
"""
466+
Make sure that the old parameter "sizes" is supported and it reports an
467+
warning.
468+
469+
Modified from the test_plot3d_sizes() test.
470+
"""
471+
fig = Figure()
472+
with pytest.warns(expected_warning=FutureWarning) as record:
473+
fig.plot3d(
474+
x=data[:, 0],
475+
y=data[:, 1],
476+
z=data[:, 2],
477+
zscale=5,
478+
perspective=[225, 30],
479+
sizes=0.5 * data[:, 2],
480+
region=region,
481+
projection="X10c",
482+
style="ui",
483+
color="blue",
484+
frame=["af", "zaf"],
485+
)
486+
assert len(record) == 1 # check that only one warning was raised
487+
return fig

0 commit comments

Comments
 (0)