Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 15 additions & 10 deletions pygmt/src/plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
plot - Plot lines, polygons, and symbols in 2-D.
"""

from collections.abc import Sequence
from typing import Literal

from pygmt._typing import PathLike, TableLike
Expand Down Expand Up @@ -44,7 +45,6 @@
i="incols",
l="label",
p="perspective",
t="transparency",
w="wrap",
)
@kwargs_to_strings(R="sequence", i="sequence_comma", p="sequence")
Expand All @@ -61,6 +61,7 @@ def plot( # noqa: PLR0912, PLR0913
verbose: Literal["quiet", "error", "warning", "timing", "info", "compat", "debug"]
| bool = False,
panel: int | tuple[int, int] | bool = False,
transparency: float | Sequence[float] | bool | None = None,
**kwargs,
):
r"""
Expand Down Expand Up @@ -91,6 +92,7 @@ def plot( # noqa: PLR0912, PLR0913
- J = projection
- V = verbose
- c = panel
- t = transparency

Parameters
----------
Expand Down Expand Up @@ -228,9 +230,8 @@ def plot( # noqa: PLR0912, PLR0913
{label}
{perspective}
{transparency}
``transparency`` can also be a 1-D array to set varying
transparency for symbols, but this option is only valid if using
``x``/``y``.
``transparency`` can also be a 1-D array to set varying transparency for
symbols, but this option is only valid if using ``x``/``y``.
{wrap}
"""
# TODO(GMT>6.5.0): Remove the note for the upstream bug of the "straight_line"
Expand All @@ -254,11 +255,14 @@ def plot( # noqa: PLR0912, PLR0913
# Size
if is_nonstr_iter(size):
data["size"] = size
# Intensity and transparency
for flag, name in [("I", "intensity"), ("t", "transparency")]:
if is_nonstr_iter(kwargs.get(flag)):
data[name] = kwargs[flag]
kwargs[flag] = ""
# Intensity
if is_nonstr_iter(kwargs.get("I")):
data["intensity"] = kwargs["I"]
kwargs["I"] = ""
# Transparency
if is_nonstr_iter(transparency):
data["transparency"] = transparency
transparency = True
# Symbol must be at the last column
if is_nonstr_iter(symbol):
if "S" not in kwargs:
Expand All @@ -273,7 +277,7 @@ def plot( # noqa: PLR0912, PLR0913
("fill", kwargs.get("G")),
("size", size),
("intensity", kwargs.get("I")),
("transparency", kwargs.get("t")),
("transparency", transparency),
("symbol", symbol),
]:
if is_nonstr_iter(value):
Expand All @@ -292,6 +296,7 @@ def plot( # noqa: PLR0912, PLR0913
J=projection,
V=verbose,
c=panel,
t=transparency,
)
aliasdict.merge(kwargs)

Expand Down
25 changes: 15 additions & 10 deletions pygmt/src/plot3d.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
plot3d - Plot lines, polygons, and symbols in 3-D.
"""

from collections.abc import Sequence
from typing import Literal

from pygmt._typing import PathLike, TableLike
Expand Down Expand Up @@ -45,7 +46,6 @@
i="incols",
l="label",
p="perspective",
t="transparency",
w="wrap",
)
@kwargs_to_strings(R="sequence", i="sequence_comma", p="sequence")
Expand All @@ -63,6 +63,7 @@ def plot3d( # noqa: PLR0912, PLR0913
verbose: Literal["quiet", "error", "warning", "timing", "info", "compat", "debug"]
| bool = False,
panel: int | tuple[int, int] | bool = False,
transparency: float | Sequence[float] | bool | None = None,
**kwargs,
):
r"""
Expand Down Expand Up @@ -93,6 +94,7 @@ def plot3d( # noqa: PLR0912, PLR0913
- J = projection
- V = verbose
- c = panel
- t = transparency

Parameters
----------
Expand Down Expand Up @@ -206,9 +208,8 @@ def plot3d( # noqa: PLR0912, PLR0913
{label}
{perspective}
{transparency}
``transparency`` can also be a 1-D array to set varying
transparency for symbols, but this option is only valid if using
``x``/``y``/``z``.
``transparency`` can also be a 1-D array to set varying transparency for
symbols, but this option is only valid if using ``x``/``y``/``z``.
{wrap}
"""
# TODO(GMT>6.5.0): Remove the note for the upstream bug of the "straight_line"
Expand All @@ -232,11 +233,14 @@ def plot3d( # noqa: PLR0912, PLR0913
# Size
if is_nonstr_iter(size):
data["size"] = size
# Intensity and transparency
for flag, name in [("I", "intensity"), ("t", "transparency")]:
if is_nonstr_iter(kwargs.get(flag)):
data[name] = kwargs[flag]
kwargs[flag] = ""
# Intensity
if is_nonstr_iter(kwargs.get("I")):
data["intensity"] = kwargs["I"]
kwargs["I"] = ""
# Transparency
if is_nonstr_iter(transparency):
data["transparency"] = transparency
transparency = True
# Symbol must be at the last column
if is_nonstr_iter(symbol):
if "S" not in kwargs:
Expand All @@ -252,7 +256,7 @@ def plot3d( # noqa: PLR0912, PLR0913
("fill", kwargs.get("G")),
("size", size),
("intensity", kwargs.get("I")),
("transparency", kwargs.get("t")),
("transparency", transparency),
("symbol", symbol),
]:
if is_nonstr_iter(value):
Expand All @@ -271,6 +275,7 @@ def plot3d( # noqa: PLR0912, PLR0913
J=projection,
V=verbose,
c=panel,
t=transparency,
)
aliasdict.merge(kwargs)

Expand Down
17 changes: 9 additions & 8 deletions pygmt/src/text.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@
h="header",
it="use_word",
p="perspective",
t="transparency",
w="wrap",
)
@kwargs_to_strings(R="sequence", p="sequence")
Expand All @@ -55,6 +54,7 @@ def text_( # noqa: PLR0912, PLR0913, PLR0915
verbose: Literal["quiet", "error", "warning", "timing", "info", "compat", "debug"]
| bool = False,
panel: int | tuple[int, int] | bool = False,
transparency: float | Sequence[float] | bool | None = None,
**kwargs,
):
r"""
Expand All @@ -78,6 +78,7 @@ def text_( # noqa: PLR0912, PLR0913, PLR0915
- J = projection
- V = verbose
- c = panel
- t = transparency

Parameters
----------
Expand Down Expand Up @@ -181,9 +182,8 @@ def text_( # noqa: PLR0912, PLR0913, PLR0915
columns can be specified.
{perspective}
{transparency}
``transparency`` can also be a 1-D array to set varying
transparency for texts, but this option is only valid if using
``x``/``y`` and ``text``.
``transparency`` can also be a 1-D array to set varying transparency for texts,
but this option is only valid if using ``x``/``y`` and ``text``.
{wrap}
"""
self._activate_figure()
Expand Down Expand Up @@ -252,9 +252,9 @@ def text_( # noqa: PLR0912, PLR0913, PLR0915

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

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

for arg, _, name in [*array_args, (kwargs.get("t"), "", "transparency")]:
for arg, _, name in [*array_args, (transparency, "", "transparency")]:
if is_nonstr_iter(arg):
raise GMTTypeError(
type(arg),
Expand All @@ -279,6 +279,7 @@ def text_( # noqa: PLR0912, PLR0913, PLR0915
J=projection,
V=verbose,
c=panel,
t=transparency,
)
aliasdict.merge(kwargs)

Expand Down
Loading