1
1
"""
2
2
plot - Plot in two dimensions.
3
3
"""
4
+ from pygmt .alias import Alias , convert_aliases
4
5
from pygmt .clib import Session
5
6
from pygmt .exceptions import GMTInvalidInput
6
7
from pygmt .helpers import (
9
10
deprecate_parameter ,
10
11
fmt_docstring ,
11
12
is_nonstr_iter ,
12
- kwargs_to_strings ,
13
- use_alias ,
14
13
)
15
14
from pygmt .src .which import which
16
15
17
16
18
17
@fmt_docstring
19
18
@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" )
52
19
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 ,
54
31
):
55
32
r"""
56
33
Plot lines, polygons, and symbols in 2-D.
@@ -75,8 +52,6 @@ def plot( # noqa: PLR0912
75
52
76
53
Full option list at :gmt-docs:`plot.html`
77
54
78
- {aliases}
79
-
80
55
Parameters
81
56
----------
82
57
data : str, {table-like}
@@ -214,54 +189,93 @@ def plot( # noqa: PLR0912
214
189
"""
215
190
kwargs = self ._preprocess (** kwargs )
216
191
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
+
217
223
kind = data_kind (data , x , y )
218
224
219
225
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 :
221
227
extra_arrays .extend (direction )
222
228
elif (
223
- kwargs . get ( "S" ) is None
229
+ style is None
224
230
and kind == "geojson"
225
231
and data .geom_type .isin (["Point" , "MultiPoint" ]).all ()
226
232
): # 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" ):
229
235
# checking that the data is a file path to set default style
230
236
try :
231
237
with open (which (data ), encoding = "utf8" ) as file :
232
238
line = file .readline ()
233
239
if "@GMULTIPOINT" in line or "@GPOINT" in line :
234
240
# if the file is gmt style and geometry is set to Point
235
- kwargs [ "S" ] = "s0.2c"
241
+ style = "s0.2c"
236
242
except FileNotFoundError :
237
243
pass
238
- if is_nonstr_iter (kwargs .get ("G" )):
244
+
245
+ if is_nonstr_iter (fill ):
239
246
if kind != "vectors" :
240
247
raise GMTInvalidInput (
241
248
"Can't use arrays for fill if data is matrix or file."
242
249
)
243
- extra_arrays .append (kwargs [ "G" ] )
244
- del kwargs [ "G" ]
250
+ extra_arrays .append (fill )
251
+ fill = None
245
252
if size is not None :
246
253
if kind != "vectors" :
247
254
raise GMTInvalidInput (
248
255
"Can't use arrays for 'size' if data is a matrix or file."
249
256
)
250
257
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
260
272
261
273
with Session () as lib :
262
274
file_context = lib .virtualfile_from_data (
263
275
check_kind = "vector" , data = data , x = x , y = y , extra_arrays = extra_arrays
264
276
)
265
277
278
+ options = convert_aliases ()
279
+ print (options )
266
280
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