11"""
22plot - Plot in two dimensions.
33"""
4+ from pygmt .alias import Alias , convert_aliases
45from pygmt .clib import Session
56from pygmt .exceptions import GMTInvalidInput
67from pygmt .helpers import (
910 deprecate_parameter ,
1011 fmt_docstring ,
1112 is_nonstr_iter ,
12- kwargs_to_strings ,
13- use_alias ,
1413)
1514from 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" )
5219def 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}
@@ -207,54 +182,92 @@ def plot( # noqa: PLR0912
207182 """
208183 kwargs = self ._preprocess (** kwargs )
209184
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+
210216 kind = data_kind (data , x , y )
211217
212218 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 :
214220 extra_arrays .extend (direction )
215221 elif (
216- kwargs . get ( "S" ) is None
222+ style is None
217223 and kind == "geojson"
218224 and data .geom_type .isin (["Point" , "MultiPoint" ]).all ()
219225 ): # 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" ):
222228 # checking that the data is a file path to set default style
223229 try :
224230 with open (which (data ), encoding = "utf8" ) as file :
225231 line = file .readline ()
226232 if "@GMULTIPOINT" in line or "@GPOINT" in line :
227233 # if the file is gmt style and geometry is set to Point
228- kwargs [ "S" ] = "s0.2c"
234+ style = "s0.2c"
229235 except FileNotFoundError :
230236 pass
231- if is_nonstr_iter (kwargs .get ("G" )):
237+
238+ if is_nonstr_iter (fill ):
232239 if kind != "vectors" :
233240 raise GMTInvalidInput (
234241 "Can't use arrays for fill if data is matrix or file."
235242 )
236- extra_arrays .append (kwargs [ "G" ] )
237- del kwargs [ "G" ]
243+ extra_arrays .append (fill )
244+ fill = None
238245 if size is not None :
239246 if kind != "vectors" :
240247 raise GMTInvalidInput (
241248 "Can't use arrays for 'size' if data is a matrix or file."
242249 )
243250 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
253265
254266 with Session () as lib :
255267 file_context = lib .virtualfile_from_data (
256268 check_kind = "vector" , data = data , x = x , y = y , extra_arrays = extra_arrays
257269 )
258270
271+ options = convert_aliases ()
259272 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