|
39 | 39 | @kwargs_to_strings(
|
40 | 40 | R="sequence",
|
41 | 41 | textfiles="sequence_space",
|
42 |
| - angle="sequence_comma", |
43 |
| - font="sequence_comma", |
44 |
| - justify="sequence_comma", |
45 | 42 | c="sequence_comma",
|
46 | 43 | p="sequence",
|
47 | 44 | )
|
@@ -97,20 +94,20 @@ def text_(
|
97 | 94 | of the map.
|
98 | 95 | text : str or 1-D array
|
99 | 96 | The text string, or an array of strings to plot on the figure.
|
100 |
| - angle: float, str, or bool |
| 97 | + angle: float, str, bool or list |
101 | 98 | Set the angle measured in degrees counter-clockwise from
|
102 | 99 | horizontal (e.g. 30 sets the text at 30 degrees). If no angle is
|
103 | 100 | explicitly given (i.e. ``angle=True``) then the input to ``textfiles``
|
104 | 101 | must have this as a column.
|
105 |
| - font : str or bool |
| 102 | + font : str, bool or list of str |
106 | 103 | Set the font specification with format *size*\ ,\ *font*\ ,\ *color*
|
107 | 104 | where *size* is text size in points, *font* is the font to use, and
|
108 | 105 | *color* sets the font color. For example,
|
109 | 106 | ``font="12p,Helvetica-Bold,red"`` selects a 12p, red, Helvetica-Bold
|
110 | 107 | font. If no font info is explicitly given (i.e. ``font=True``), then
|
111 | 108 | the input to ``textfiles`` must have this information in one of its
|
112 | 109 | columns.
|
113 |
| - justify : str or bool |
| 110 | + justify : str, bool or list of str |
114 | 111 | Set the alignment which refers to the part of the text string that
|
115 | 112 | will be mapped onto the (x, y) point. Choose a two-letter
|
116 | 113 | combination of **L**, **C**, **R** (for left, center, or right) and
|
@@ -170,7 +167,7 @@ def text_(
|
170 | 167 | ``x``/``y`` and ``text``.
|
171 | 168 | {wrap}
|
172 | 169 | """
|
173 |
| - # pylint: disable=too-many-branches |
| 170 | + # pylint: disable=too-many-branches,too-many-locals |
174 | 171 | kwargs = self._preprocess(**kwargs) # pylint: disable=protected-access
|
175 | 172 |
|
176 | 173 | # Ensure inputs are either textfiles, x/y/text, or position/text
|
@@ -201,25 +198,22 @@ def text_(
|
201 | 198 | ):
|
202 | 199 | kwargs.update({"F": ""})
|
203 | 200 |
|
204 |
| - if angle is True: |
205 |
| - kwargs["F"] += "+a" |
206 |
| - elif isinstance(angle, (int, float, str)): |
207 |
| - kwargs["F"] += f"+a{str(angle)}" |
208 |
| - |
209 |
| - if font is True: |
210 |
| - kwargs["F"] += "+f" |
211 |
| - elif isinstance(font, str): |
212 |
| - kwargs["F"] += f"+f{font}" |
213 |
| - |
214 |
| - if justify is True: |
215 |
| - kwargs["F"] += "+j" |
216 |
| - elif isinstance(justify, str): |
217 |
| - kwargs["F"] += f"+j{justify}" |
| 201 | + extra_arrays = [] |
| 202 | + for arg, flag in [(angle, "+a"), (font, "+f"), (justify, "+j")]: |
| 203 | + if arg is True: |
| 204 | + kwargs["F"] += flag |
| 205 | + elif is_nonstr_iter(arg): |
| 206 | + kwargs["F"] += flag |
| 207 | + if flag == "+a": # angle is numeric type |
| 208 | + extra_arrays.append(np.atleast_1d(arg)) |
| 209 | + else: # font or justify is str type |
| 210 | + extra_arrays.append(np.atleast_1d(arg).astype(str)) |
| 211 | + elif isinstance(arg, (int, float, str)): |
| 212 | + kwargs["F"] += f"{flag}{arg}" |
218 | 213 |
|
219 | 214 | if isinstance(position, str):
|
220 | 215 | kwargs["F"] += f"+c{position}+t{text}"
|
221 | 216 |
|
222 |
| - extra_arrays = [] |
223 | 217 | # If an array of transparency is given, GMT will read it from
|
224 | 218 | # the last numerical column per data record.
|
225 | 219 | if kwargs.get("t") is not None and is_nonstr_iter(kwargs["t"]):
|
|
0 commit comments