2
2
text - Plot text on a figure.
3
3
"""
4
4
import numpy as np
5
+ from pygmt .alias import Alias , convert_aliases
5
6
from pygmt .clib import Session
6
7
from pygmt .exceptions import GMTInvalidInput
7
8
from pygmt .helpers import (
11
12
is_nonstr_iter ,
12
13
kwargs_to_strings ,
13
14
non_ascii_to_octal ,
14
- use_alias ,
15
15
)
16
16
17
17
18
18
@fmt_docstring
19
- @use_alias (
20
- R = "region" ,
21
- J = "projection" ,
22
- B = "frame" ,
23
- C = "clearance" ,
24
- D = "offset" ,
25
- G = "fill" ,
26
- N = "no_clip" ,
27
- V = "verbose" ,
28
- W = "pen" ,
29
- a = "aspatial" ,
30
- c = "panel" ,
31
- e = "find" ,
32
- f = "coltypes" ,
33
- h = "header" ,
34
- it = "use_word" ,
35
- p = "perspective" ,
36
- t = "transparency" ,
37
- w = "wrap" ,
38
- )
39
- @kwargs_to_strings (
40
- R = "sequence" ,
41
- textfiles = "sequence_space" ,
42
- c = "sequence_comma" ,
43
- p = "sequence" ,
44
- )
45
- def text_ ( # noqa: PLR0912
19
+ @kwargs_to_strings (textfiles = "sequence_space" )
20
+ def text_ ( # noqa: PLR0913
46
21
self ,
47
22
textfiles = None ,
48
23
x = None ,
@@ -52,6 +27,9 @@ def text_( # noqa: PLR0912
52
27
angle = None ,
53
28
font = None ,
54
29
justify = None ,
30
+ projection = None , # noqa: ARG001
31
+ region = None , # noqa: ARG001
32
+ transparency = None ,
55
33
** kwargs ,
56
34
):
57
35
r"""
@@ -71,8 +49,6 @@ def text_( # noqa: PLR0912
71
49
72
50
Full option list at :gmt-docs:`text.html`
73
51
74
- {aliases}
75
-
76
52
Parameters
77
53
----------
78
54
textfiles : str or list
@@ -182,6 +158,31 @@ def text_( # noqa: PLR0912
182
158
"""
183
159
kwargs = self ._preprocess (** kwargs )
184
160
161
+ _aliases = [
162
+ Alias ("position" , "F" , "+c" , "" ),
163
+ Alias ("angle" , "F" , "+a" , "" ),
164
+ Alias ("font" , "F" , "+f" , "" ),
165
+ Alias ("justify" , "F" , "+j" , "" ),
166
+ Alias ("region" , "R" , "" , "/" ),
167
+ Alias ("projection" , "J" , "" , "" ),
168
+ Alias ("transparency" , "t" , "" , "" ),
169
+ Alias ("frame" , "B" , "" , "" ),
170
+ Alias ("clearance" , "C" , "" , "" ),
171
+ Alias ("offset" , "D" , "" , "" ),
172
+ Alias ("fill" , "G" , "" , "" ),
173
+ Alias ("no_clip" , "N" , "" , "" ),
174
+ Alias ("verbose" , "V" , "" , "" ),
175
+ Alias ("pen" , "W" , "" , "" ),
176
+ Alias ("aspatial" , "a" , "" , "" ),
177
+ Alias ("panel" , "c" , "" , "," ),
178
+ Alias ("find" , "e" , "" , "" ),
179
+ Alias ("coltypes" , "f" , "" , "" ),
180
+ Alias ("header" , "h" , "" , "" ),
181
+ Alias ("use_word" , "it" , "" , "" ),
182
+ Alias ("perspective" , "p" , "" , "/" ),
183
+ Alias ("wrap" , "w" , "" , "" ),
184
+ ]
185
+
185
186
# Ensure inputs are either textfiles, x/y/text, or position/text
186
187
if position is None :
187
188
if (x is not None or y is not None ) and textfiles is not None :
@@ -201,33 +202,22 @@ def text_( # noqa: PLR0912
201
202
kind = None
202
203
textfiles = ""
203
204
204
- # Build the -F option in gmt text.
205
- if kwargs .get ("F" ) is None and any (
206
- v is not None for v in (position , angle , font , justify )
207
- ):
208
- kwargs .update ({"F" : "" })
205
+ # special handling with the position parameter
206
+ if position is not None :
207
+ position += f"+t{ text } "
209
208
210
209
extra_arrays = []
211
- for arg , flag in [(angle , "+a" ), (font , "+f" ), (justify , "+j" )]:
212
- if arg is True :
213
- kwargs ["F" ] += flag
214
- elif is_nonstr_iter (arg ):
215
- kwargs ["F" ] += flag
216
- if flag == "+a" : # angle is numeric type
217
- extra_arrays .append (np .atleast_1d (arg ))
218
- else : # font or justify is str type
219
- extra_arrays .append (np .atleast_1d (arg ).astype (str ))
220
- elif isinstance (arg , (int , float , str )):
221
- kwargs ["F" ] += f"{ flag } { arg } "
222
-
223
- if isinstance (position , str ):
224
- kwargs ["F" ] += f"+c{ position } +t{ text } "
225
-
210
+ # angle is numeric type
211
+ if is_nonstr_iter (angle ):
212
+ extra_arrays .append (np .atleast_1d (angle ))
213
+ # font or justify is str type
214
+ for arg in (font , justify ):
215
+ if is_nonstr_iter (arg ):
216
+ extra_arrays .append (np .atleast_1d (arg ).astype (str )) # noqa: PERF401
226
217
# If an array of transparency is given, GMT will read it from
227
218
# the last numerical column per data record.
228
- if is_nonstr_iter (kwargs .get ("t" )):
229
- extra_arrays .append (kwargs ["t" ])
230
- kwargs ["t" ] = ""
219
+ if is_nonstr_iter (transparency ):
220
+ extra_arrays .append (transparency )
231
221
232
222
# Append text at last column. Text must be passed in as str type.
233
223
if kind == "vectors" :
@@ -239,5 +229,6 @@ def text_( # noqa: PLR0912
239
229
file_context = lib .virtualfile_from_data (
240
230
check_kind = "vector" , data = textfiles , x = x , y = y , extra_arrays = extra_arrays
241
231
)
232
+ options = convert_aliases ()
242
233
with file_context as fname :
243
- lib .call_module (module = "text" , args = build_arg_string (kwargs , infile = fname ))
234
+ lib .call_module (module = "text" , args = build_arg_string (options , infile = fname ))
0 commit comments