Skip to content

Commit 1669d51

Browse files
authored
Figure.plot/Figure.plot3d/Figure.text: Migrate the transparency parameter to the new alias system (#4068)
1 parent 5d2da64 commit 1669d51

File tree

3 files changed

+39
-28
lines changed

3 files changed

+39
-28
lines changed

pygmt/src/plot.py

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
plot - Plot lines, polygons, and symbols in 2-D.
33
"""
44

5+
from collections.abc import Sequence
56
from typing import Literal
67

78
from pygmt._typing import PathLike, TableLike
@@ -44,7 +45,6 @@
4445
i="incols",
4546
l="label",
4647
p="perspective",
47-
t="transparency",
4848
w="wrap",
4949
)
5050
@kwargs_to_strings(R="sequence", i="sequence_comma", p="sequence")
@@ -61,6 +61,7 @@ def plot( # noqa: PLR0912, PLR0913
6161
verbose: Literal["quiet", "error", "warning", "timing", "info", "compat", "debug"]
6262
| bool = False,
6363
panel: int | tuple[int, int] | bool = False,
64+
transparency: float | Sequence[float] | bool | None = None,
6465
**kwargs,
6566
):
6667
r"""
@@ -91,6 +92,7 @@ def plot( # noqa: PLR0912, PLR0913
9192
- J = projection
9293
- V = verbose
9394
- c = panel
95+
- t = transparency
9496
9597
Parameters
9698
----------
@@ -228,9 +230,8 @@ def plot( # noqa: PLR0912, PLR0913
228230
{label}
229231
{perspective}
230232
{transparency}
231-
``transparency`` can also be a 1-D array to set varying
232-
transparency for symbols, but this option is only valid if using
233-
``x``/``y``.
233+
``transparency`` can also be a 1-D array to set varying transparency for
234+
symbols, but this option is only valid if using ``x``/``y``.
234235
{wrap}
235236
"""
236237
# TODO(GMT>6.5.0): Remove the note for the upstream bug of the "straight_line"
@@ -254,11 +255,14 @@ def plot( # noqa: PLR0912, PLR0913
254255
# Size
255256
if is_nonstr_iter(size):
256257
data["size"] = size
257-
# Intensity and transparency
258-
for flag, name in [("I", "intensity"), ("t", "transparency")]:
259-
if is_nonstr_iter(kwargs.get(flag)):
260-
data[name] = kwargs[flag]
261-
kwargs[flag] = ""
258+
# Intensity
259+
if is_nonstr_iter(kwargs.get("I")):
260+
data["intensity"] = kwargs["I"]
261+
kwargs["I"] = ""
262+
# Transparency
263+
if is_nonstr_iter(transparency):
264+
data["transparency"] = transparency
265+
transparency = True
262266
# Symbol must be at the last column
263267
if is_nonstr_iter(symbol):
264268
if "S" not in kwargs:
@@ -273,7 +277,7 @@ def plot( # noqa: PLR0912, PLR0913
273277
("fill", kwargs.get("G")),
274278
("size", size),
275279
("intensity", kwargs.get("I")),
276-
("transparency", kwargs.get("t")),
280+
("transparency", transparency),
277281
("symbol", symbol),
278282
]:
279283
if is_nonstr_iter(value):
@@ -292,6 +296,7 @@ def plot( # noqa: PLR0912, PLR0913
292296
J=projection,
293297
V=verbose,
294298
c=panel,
299+
t=transparency,
295300
)
296301
aliasdict.merge(kwargs)
297302

pygmt/src/plot3d.py

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
plot3d - Plot lines, polygons, and symbols in 3-D.
33
"""
44

5+
from collections.abc import Sequence
56
from typing import Literal
67

78
from pygmt._typing import PathLike, TableLike
@@ -45,7 +46,6 @@
4546
i="incols",
4647
l="label",
4748
p="perspective",
48-
t="transparency",
4949
w="wrap",
5050
)
5151
@kwargs_to_strings(R="sequence", i="sequence_comma", p="sequence")
@@ -63,6 +63,7 @@ def plot3d( # noqa: PLR0912, PLR0913
6363
verbose: Literal["quiet", "error", "warning", "timing", "info", "compat", "debug"]
6464
| bool = False,
6565
panel: int | tuple[int, int] | bool = False,
66+
transparency: float | Sequence[float] | bool | None = None,
6667
**kwargs,
6768
):
6869
r"""
@@ -93,6 +94,7 @@ def plot3d( # noqa: PLR0912, PLR0913
9394
- J = projection
9495
- V = verbose
9596
- c = panel
97+
- t = transparency
9698
9799
Parameters
98100
----------
@@ -206,9 +208,8 @@ def plot3d( # noqa: PLR0912, PLR0913
206208
{label}
207209
{perspective}
208210
{transparency}
209-
``transparency`` can also be a 1-D array to set varying
210-
transparency for symbols, but this option is only valid if using
211-
``x``/``y``/``z``.
211+
``transparency`` can also be a 1-D array to set varying transparency for
212+
symbols, but this option is only valid if using ``x``/``y``/``z``.
212213
{wrap}
213214
"""
214215
# TODO(GMT>6.5.0): Remove the note for the upstream bug of the "straight_line"
@@ -232,11 +233,14 @@ def plot3d( # noqa: PLR0912, PLR0913
232233
# Size
233234
if is_nonstr_iter(size):
234235
data["size"] = size
235-
# Intensity and transparency
236-
for flag, name in [("I", "intensity"), ("t", "transparency")]:
237-
if is_nonstr_iter(kwargs.get(flag)):
238-
data[name] = kwargs[flag]
239-
kwargs[flag] = ""
236+
# Intensity
237+
if is_nonstr_iter(kwargs.get("I")):
238+
data["intensity"] = kwargs["I"]
239+
kwargs["I"] = ""
240+
# Transparency
241+
if is_nonstr_iter(transparency):
242+
data["transparency"] = transparency
243+
transparency = True
240244
# Symbol must be at the last column
241245
if is_nonstr_iter(symbol):
242246
if "S" not in kwargs:
@@ -252,7 +256,7 @@ def plot3d( # noqa: PLR0912, PLR0913
252256
("fill", kwargs.get("G")),
253257
("size", size),
254258
("intensity", kwargs.get("I")),
255-
("transparency", kwargs.get("t")),
259+
("transparency", transparency),
256260
("symbol", symbol),
257261
]:
258262
if is_nonstr_iter(value):
@@ -271,6 +275,7 @@ def plot3d( # noqa: PLR0912, PLR0913
271275
J=projection,
272276
V=verbose,
273277
c=panel,
278+
t=transparency,
274279
)
275280
aliasdict.merge(kwargs)
276281

pygmt/src/text.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@
3737
h="header",
3838
it="use_word",
3939
p="perspective",
40-
t="transparency",
4140
w="wrap",
4241
)
4342
@kwargs_to_strings(R="sequence", p="sequence")
@@ -55,6 +54,7 @@ def text_( # noqa: PLR0912, PLR0913, PLR0915
5554
verbose: Literal["quiet", "error", "warning", "timing", "info", "compat", "debug"]
5655
| bool = False,
5756
panel: int | tuple[int, int] | bool = False,
57+
transparency: float | Sequence[float] | bool | None = None,
5858
**kwargs,
5959
):
6060
r"""
@@ -78,6 +78,7 @@ def text_( # noqa: PLR0912, PLR0913, PLR0915
7878
- J = projection
7979
- V = verbose
8080
- c = panel
81+
- t = transparency
8182
8283
Parameters
8384
----------
@@ -181,9 +182,8 @@ def text_( # noqa: PLR0912, PLR0913, PLR0915
181182
columns can be specified.
182183
{perspective}
183184
{transparency}
184-
``transparency`` can also be a 1-D array to set varying
185-
transparency for texts, but this option is only valid if using
186-
``x``/``y`` and ``text``.
185+
``transparency`` can also be a 1-D array to set varying transparency for texts,
186+
but this option is only valid if using ``x``/``y`` and ``text``.
187187
{wrap}
188188
"""
189189
self._activate_figure()
@@ -252,9 +252,9 @@ def text_( # noqa: PLR0912, PLR0913, PLR0915
252252

253253
# If an array of transparency is given, GMT will read it from the last numerical
254254
# column per data record.
255-
if is_nonstr_iter(kwargs.get("t")):
256-
data["transparency"] = kwargs["t"]
257-
kwargs["t"] = True
255+
if is_nonstr_iter(transparency):
256+
data["transparency"] = transparency
257+
transparency = True
258258

259259
# Append text to the last column. Text must be passed in as str type.
260260
text = np.asarray(text, dtype=np.str_)
@@ -268,7 +268,7 @@ def text_( # noqa: PLR0912, PLR0913, PLR0915
268268
if isinstance(position, str):
269269
kwargs["F"] += f"+c{position}+t{text}"
270270

271-
for arg, _, name in [*array_args, (kwargs.get("t"), "", "transparency")]:
271+
for arg, _, name in [*array_args, (transparency, "", "transparency")]:
272272
if is_nonstr_iter(arg):
273273
raise GMTTypeError(
274274
type(arg),
@@ -279,6 +279,7 @@ def text_( # noqa: PLR0912, PLR0913, PLR0915
279279
J=projection,
280280
V=verbose,
281281
c=panel,
282+
t=transparency,
282283
)
283284
aliasdict.merge(kwargs)
284285

0 commit comments

Comments
 (0)