Skip to content

Commit 4d24b5e

Browse files
committed
Update plot
1 parent 20f2c78 commit 4d24b5e

File tree

1 file changed

+69
-55
lines changed

1 file changed

+69
-55
lines changed

pygmt/src/plot.py

Lines changed: 69 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
"""
22
plot - Plot in two dimensions.
33
"""
4+
from pygmt.alias import Alias, convert_aliases
45
from pygmt.clib import Session
56
from pygmt.exceptions import GMTInvalidInput
67
from pygmt.helpers import (
@@ -9,48 +10,24 @@
910
deprecate_parameter,
1011
fmt_docstring,
1112
is_nonstr_iter,
12-
kwargs_to_strings,
13-
use_alias,
1413
)
1514
from pygmt.src.which import which
1615

1716

1817
@fmt_docstring
1918
@deprecate_parameter("color", "fill", "v0.8.0", remove_version="v0.12.0")
20-
@use_alias(
21-
A="straight_line",
22-
B="frame",
23-
C="cmap",
24-
D="offset",
25-
E="error_bar",
26-
F="connection",
27-
G="fill",
28-
I="intensity",
29-
J="projection",
30-
L="close",
31-
N="no_clip",
32-
R="region",
33-
S="style",
34-
V="verbose",
35-
W="pen",
36-
Z="zvalue",
37-
a="aspatial",
38-
b="binary",
39-
c="panel",
40-
d="nodata",
41-
e="find",
42-
f="coltypes",
43-
g="gap",
44-
h="header",
45-
i="incols",
46-
l="label",
47-
p="perspective",
48-
t="transparency",
49-
w="wrap",
50-
)
51-
@kwargs_to_strings(R="sequence", c="sequence_comma", i="sequence_comma", p="sequence")
5219
def plot( # noqa: PLR0912
53-
self, data=None, x=None, y=None, size=None, direction=None, **kwargs
20+
self,
21+
data=None,
22+
x=None,
23+
y=None,
24+
size=None,
25+
direction=None,
26+
style=None,
27+
fill=None,
28+
transparency=None,
29+
intensity=None,
30+
**kwargs,
5431
):
5532
r"""
5633
Plot lines, polygons, and symbols in 2-D.
@@ -75,8 +52,6 @@ def plot( # noqa: PLR0912
7552
7653
Full option list at :gmt-docs:`plot.html`
7754
78-
{aliases}
79-
8055
Parameters
8156
----------
8257
data : str, {table-like}
@@ -214,54 +189,93 @@ def plot( # noqa: PLR0912
214189
"""
215190
kwargs = self._preprocess(**kwargs)
216191

192+
_aliases = [
193+
Alias("straight_line", "A", "", ""),
194+
Alias("frame", "B", "", ""),
195+
Alias("cmap", "C", "", ""),
196+
Alias("offset", "D", "", ""),
197+
Alias("error_bar", "E", "", ""),
198+
Alias("connection", "F", "", ""),
199+
Alias("fill", "G", "", ""),
200+
Alias("intensity", "I", "", ""),
201+
Alias("projection", "J", "", ""),
202+
Alias("close", "L", "", ""),
203+
Alias("no_clip", "N", "", ""),
204+
Alias("region", "R", "", "/"),
205+
Alias("style", "S", "", ""),
206+
Alias("verbose", "V", "", ""),
207+
Alias("pen", "W", "", ""),
208+
Alias("zvalue", "Z", "", ""),
209+
Alias("aspatial", "a", "", ""),
210+
Alias("binary", "b", "", ""),
211+
Alias("panel", "c", "", ","),
212+
Alias("find", "e", "", ""),
213+
Alias("coltypes", "f", "", ""),
214+
Alias("gap", "g", "", ""),
215+
Alias("header", "h", "", ""),
216+
Alias("incols", "i", "", ","),
217+
Alias("lable", "l", "", ""),
218+
Alias("perspective", "p", "", "/"),
219+
Alias("transparency", "t", "", ""),
220+
Alias("wrap", "w", "", ""),
221+
]
222+
217223
kind = data_kind(data, x, y)
218224

219225
extra_arrays = []
220-
if kwargs.get("S") is not None and kwargs["S"][0] in "vV" and direction is not None:
226+
if style is not None and style[0] in "vV" and direction is not None:
221227
extra_arrays.extend(direction)
222228
elif (
223-
kwargs.get("S") is None
229+
style is None
224230
and kind == "geojson"
225231
and data.geom_type.isin(["Point", "MultiPoint"]).all()
226232
): # checking if the geometry of a geoDataFrame is Point or MultiPoint
227-
kwargs["S"] = "s0.2c"
228-
elif kwargs.get("S") is None and kind == "file" and str(data).endswith(".gmt"):
233+
style = "s0.2c"
234+
elif style is None and kind == "file" and str(data).endswith(".gmt"):
229235
# checking that the data is a file path to set default style
230236
try:
231237
with open(which(data), encoding="utf8") as file:
232238
line = file.readline()
233239
if "@GMULTIPOINT" in line or "@GPOINT" in line:
234240
# if the file is gmt style and geometry is set to Point
235-
kwargs["S"] = "s0.2c"
241+
style = "s0.2c"
236242
except FileNotFoundError:
237243
pass
238-
if is_nonstr_iter(kwargs.get("G")):
244+
245+
if is_nonstr_iter(fill):
239246
if kind != "vectors":
240247
raise GMTInvalidInput(
241248
"Can't use arrays for fill if data is matrix or file."
242249
)
243-
extra_arrays.append(kwargs["G"])
244-
del kwargs["G"]
250+
extra_arrays.append(fill)
251+
fill = None
245252
if size is not None:
246253
if kind != "vectors":
247254
raise GMTInvalidInput(
248255
"Can't use arrays for 'size' if data is a matrix or file."
249256
)
250257
extra_arrays.append(size)
251-
252-
for flag in ["I", "t"]:
253-
if is_nonstr_iter(kwargs.get(flag)):
254-
if kind != "vectors":
255-
raise GMTInvalidInput(
256-
f"Can't use arrays for {plot.aliases[flag]} if data is matrix or file."
257-
)
258-
extra_arrays.append(kwargs[flag])
259-
kwargs[flag] = ""
258+
if is_nonstr_iter(intensity):
259+
if kind != "vectors":
260+
raise GMTInvalidInput(
261+
"Can't use arrays for intensity if data is matrix or file."
262+
)
263+
extra_arrays.append(intensity)
264+
intensity = True
265+
if is_nonstr_iter(transparency):
266+
if kind != "vectors":
267+
raise GMTInvalidInput(
268+
"Can't use arrays for transparency if data is matrix or file."
269+
)
270+
extra_arrays.append(transparency)
271+
transparency = True
260272

261273
with Session() as lib:
262274
file_context = lib.virtualfile_from_data(
263275
check_kind="vector", data=data, x=x, y=y, extra_arrays=extra_arrays
264276
)
265277

278+
options = convert_aliases()
279+
print(options)
266280
with file_context as fname:
267-
lib.call_module(module="plot", args=build_arg_string(kwargs, infile=fname))
281+
lib.call_module(module="plot", args=build_arg_string(options, infile=fname))

0 commit comments

Comments
 (0)