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}
@@ -207,54 +182,92 @@ def plot( # noqa: PLR0912
207
182
"""
208
183
kwargs = self ._preprocess (** kwargs )
209
184
185
+ _aliases = [
186
+ Alias ("straight_line" , "A" , "" , "" ),
187
+ Alias ("frame" , "B" , "" , "" ),
188
+ Alias ("cmap" , "C" , "" , "" ),
189
+ Alias ("offset" , "D" , "" , "" ),
190
+ Alias ("error_bar" , "E" , "" , "" ),
191
+ Alias ("connection" , "F" , "" , "" ),
192
+ Alias ("fill" , "G" , "" , "" ),
193
+ Alias ("intensity" , "I" , "" , "" ),
194
+ Alias ("projection" , "J" , "" , "" ),
195
+ Alias ("close" , "L" , "" , "" ),
196
+ Alias ("no_clip" , "N" , "" , "" ),
197
+ Alias ("region" , "R" , "" , "/" ),
198
+ Alias ("style" , "S" , "" , "" ),
199
+ Alias ("verbose" , "V" , "" , "" ),
200
+ Alias ("pen" , "W" , "" , "" ),
201
+ Alias ("zvalue" , "Z" , "" , "" ),
202
+ Alias ("aspatial" , "a" , "" , "" ),
203
+ Alias ("binary" , "b" , "" , "" ),
204
+ Alias ("panel" , "c" , "" , "," ),
205
+ Alias ("find" , "e" , "" , "" ),
206
+ Alias ("coltypes" , "f" , "" , "" ),
207
+ Alias ("gap" , "g" , "" , "" ),
208
+ Alias ("header" , "h" , "" , "" ),
209
+ Alias ("incols" , "i" , "" , "," ),
210
+ Alias ("lable" , "l" , "" , "" ),
211
+ Alias ("perspective" , "p" , "" , "/" ),
212
+ Alias ("transparency" , "t" , "" , "" ),
213
+ Alias ("wrap" , "w" , "" , "" ),
214
+ ]
215
+
210
216
kind = data_kind (data , x , y )
211
217
212
218
extra_arrays = []
213
- if kwargs . get ( "S" ) is not None and kwargs [ "S" ] [0 ] in "vV" and direction is not None :
219
+ if style is not None and style [0 ] in "vV" and direction is not None :
214
220
extra_arrays .extend (direction )
215
221
elif (
216
- kwargs . get ( "S" ) is None
222
+ style is None
217
223
and kind == "geojson"
218
224
and data .geom_type .isin (["Point" , "MultiPoint" ]).all ()
219
225
): # checking if the geometry of a geoDataFrame is Point or MultiPoint
220
- kwargs [ "S" ] = "s0.2c"
221
- elif kwargs . get ( "S" ) is None and kind == "file" and str (data ).endswith (".gmt" ):
226
+ style = "s0.2c"
227
+ elif style is None and kind == "file" and str (data ).endswith (".gmt" ):
222
228
# checking that the data is a file path to set default style
223
229
try :
224
230
with open (which (data ), encoding = "utf8" ) as file :
225
231
line = file .readline ()
226
232
if "@GMULTIPOINT" in line or "@GPOINT" in line :
227
233
# if the file is gmt style and geometry is set to Point
228
- kwargs [ "S" ] = "s0.2c"
234
+ style = "s0.2c"
229
235
except FileNotFoundError :
230
236
pass
231
- if is_nonstr_iter (kwargs .get ("G" )):
237
+
238
+ if is_nonstr_iter (fill ):
232
239
if kind != "vectors" :
233
240
raise GMTInvalidInput (
234
241
"Can't use arrays for fill if data is matrix or file."
235
242
)
236
- extra_arrays .append (kwargs [ "G" ] )
237
- del kwargs [ "G" ]
243
+ extra_arrays .append (fill )
244
+ fill = None
238
245
if size is not None :
239
246
if kind != "vectors" :
240
247
raise GMTInvalidInput (
241
248
"Can't use arrays for 'size' if data is a matrix or file."
242
249
)
243
250
extra_arrays .append (size )
244
-
245
- for flag in ["I" , "t" ]:
246
- if is_nonstr_iter (kwargs .get (flag )):
247
- if kind != "vectors" :
248
- raise GMTInvalidInput (
249
- f"Can't use arrays for { plot .aliases [flag ]} if data is matrix or file."
250
- )
251
- extra_arrays .append (kwargs [flag ])
252
- kwargs [flag ] = ""
251
+ if is_nonstr_iter (intensity ):
252
+ if kind != "vectors" :
253
+ raise GMTInvalidInput (
254
+ "Can't use arrays for intensity if data is matrix or file."
255
+ )
256
+ extra_arrays .append (intensity )
257
+ intensity = True
258
+ if is_nonstr_iter (transparency ):
259
+ if kind != "vectors" :
260
+ raise GMTInvalidInput (
261
+ "Can't use arrays for transparency if data is matrix or file."
262
+ )
263
+ extra_arrays .append (transparency )
264
+ transparency = True
253
265
254
266
with Session () as lib :
255
267
file_context = lib .virtualfile_from_data (
256
268
check_kind = "vector" , data = data , x = x , y = y , extra_arrays = extra_arrays
257
269
)
258
270
271
+ options = convert_aliases ()
259
272
with file_context as fname :
260
- lib .call_module (module = "plot" , args = build_arg_string (kwargs , infile = fname ))
273
+ lib .call_module (module = "plot" , args = build_arg_string (options , infile = fname ))
0 commit comments