Skip to content

Commit a553d68

Browse files
authored
Figure.plot: Reorder input parameters to "data, x, y" (#1547)
* Update plot.py * add decorator * adjust test_plot_datetime * adjust gallery examples
1 parent b5f825e commit a553d68

File tree

4 files changed

+17
-15
lines changed

4 files changed

+17
-15
lines changed

examples/gallery/symbols/datetime_inputs.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,26 +41,26 @@
4141
# numpy.datetime64 types
4242
x = np.array(["2010-06-01", "2011-06-01T12", "2012-01-01T12:34:56"], dtype="datetime64")
4343
y = [1, 2, 3]
44-
fig.plot(x, y, style="c0.4c", pen="1p", color="red3")
44+
fig.plot(x=x, y=y, style="c0.4c", pen="1p", color="red3")
4545

4646
# pandas.DatetimeIndex
4747
x = pd.date_range("2013", periods=3, freq="YS")
4848
y = [4, 5, 6]
49-
fig.plot(x, y, style="t0.4c", pen="1p", color="gold")
49+
fig.plot(x=x, y=y, style="t0.4c", pen="1p", color="gold")
5050

5151
# xarray.DataArray
5252
x = xr.DataArray(data=pd.date_range(start="2015-03", periods=3, freq="QS"))
5353
y = [7.5, 6, 4.5]
54-
fig.plot(x, y, style="s0.4c", pen="1p")
54+
fig.plot(x=x, y=y, style="s0.4c", pen="1p")
5555

5656
# raw datetime strings
5757
x = ["2016-02-01", "2016-06-04T14", "2016-10-04T00:00:15"]
5858
y = [7, 8, 9]
59-
fig.plot(x, y, style="a0.4c", pen="1p", color="dodgerblue")
59+
fig.plot(x=x, y=y, style="a0.4c", pen="1p", color="dodgerblue")
6060

6161
# the Python built-in datetime and date
6262
x = [datetime.date(2018, 1, 1), datetime.datetime(2019, 6, 1, 20, 5, 45)]
6363
y = [6.5, 4.5]
64-
fig.plot(x, y, style="i0.4c", pen="1p", color="seagreen")
64+
fig.plot(x=x, y=y, style="i0.4c", pen="1p", color="seagreen")
6565

6666
fig.show()

examples/gallery/symbols/points.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,5 @@
1919
# data region
2020
fig.basemap(region=region, projection="X15c", frame=True)
2121
# Plot using inverted triangles (i) of 0.5 cm size
22-
fig.plot(x, y, style="i0.5c", color="black")
22+
fig.plot(x=x, y=y, style="i0.5c", color="black")
2323
fig.show()

pygmt/src/plot.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
from pygmt.exceptions import GMTInvalidInput
66
from pygmt.helpers import (
77
build_arg_string,
8+
check_data_input_order,
89
data_kind,
910
deprecate_parameter,
1011
fmt_docstring,
@@ -18,6 +19,7 @@
1819
@fmt_docstring
1920
@deprecate_parameter("sizes", "size", "v0.4.0", remove_version="v0.6.0")
2021
@deprecate_parameter("columns", "incols", "v0.4.0", remove_version="v0.6.0")
22+
@check_data_input_order("v0.5.0", remove_version="v0.7.0")
2123
@use_alias(
2224
A="straight_line",
2325
B="frame",
@@ -53,7 +55,7 @@
5355
w="wrap",
5456
)
5557
@kwargs_to_strings(R="sequence", c="sequence_comma", i="sequence_comma", p="sequence")
56-
def plot(self, x=None, y=None, data=None, size=None, direction=None, **kwargs):
58+
def plot(self, data=None, x=None, y=None, size=None, direction=None, **kwargs):
5759
r"""
5860
Plot lines, polygons, and symbols in 2-D.
5961
@@ -81,14 +83,14 @@ def plot(self, x=None, y=None, data=None, size=None, direction=None, **kwargs):
8183
8284
Parameters
8385
----------
84-
x/y : float or 1d arrays
85-
The x and y coordinates, or arrays of x and y coordinates of the
86-
data points
8786
data : str or {table-like}
8887
Pass in either a file name to an ASCII data table, a 2D
8988
{table-classes}.
9089
Use parameter ``incols`` to choose which columns are x, y, color, and
9190
size, respectively.
91+
x/y : float or 1d arrays
92+
The x and y coordinates, or arrays of x and y coordinates of the
93+
data points
9294
size : 1d array
9395
The size of the data points in units specified using ``style``.
9496
Only valid if using ``x``/``y``.

pygmt/tests/test_plot.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -435,27 +435,27 @@ def test_plot_datetime():
435435
["2010-06-01", "2011-06-01T12", "2012-01-01T12:34:56"], dtype="datetime64"
436436
)
437437
y = [1.0, 2.0, 3.0]
438-
fig.plot(x, y, style="c0.2c", pen="1p")
438+
fig.plot(x=x, y=y, style="c0.2c", pen="1p")
439439

440440
# pandas.DatetimeIndex
441441
x = pd.date_range("2013", freq="YS", periods=3)
442442
y = [4, 5, 6]
443-
fig.plot(x, y, style="t0.2c", pen="1p")
443+
fig.plot(x=x, y=y, style="t0.2c", pen="1p")
444444

445445
# xarray.DataArray
446446
x = xr.DataArray(data=pd.date_range(start="2015-03", freq="QS", periods=3))
447447
y = [7.5, 6, 4.5]
448-
fig.plot(x, y, style="s0.2c", pen="1p")
448+
fig.plot(x=x, y=y, style="s0.2c", pen="1p")
449449

450450
# raw datetime strings
451451
x = ["2016-02-01", "2017-03-04T00:00"]
452452
y = [7, 8]
453-
fig.plot(x, y, style="a0.2c", pen="1p")
453+
fig.plot(x=x, y=y, style="a0.2c", pen="1p")
454454

455455
# the Python built-in datetime and date
456456
x = [datetime.date(2018, 1, 1), datetime.datetime(2019, 1, 1)]
457457
y = [8.5, 9.5]
458-
fig.plot(x, y, style="i0.2c", pen="1p")
458+
fig.plot(x=x, y=y, style="i0.2c", pen="1p")
459459
return fig
460460

461461

0 commit comments

Comments
 (0)