Skip to content

Commit 3682098

Browse files
committed
Improve Figure.legend
1 parent 1a2d336 commit 3682098

File tree

1 file changed

+7
-8
lines changed

1 file changed

+7
-8
lines changed

pygmt/src/legend.py

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,8 @@ def legend(
5555
The legend specification. It can be:
5656
5757
- ``None`` for using the automatically generated legend specification file.
58-
- A *filename* pointing to the legend specification file.
58+
- A string or a :class:`pathlib.PurePath` object pointing to the legend
59+
specification file.
5960
- A :class:`io.StringIO` object containing the legend specification.
6061
6162
See :gmt-docs:`legend.html` for the definition of the legend specification.
@@ -88,14 +89,12 @@ def legend(
8889
if kwargs.get("F") is None:
8990
kwargs["F"] = box
9091

91-
if spec is None:
92-
specfile = ""
93-
else:
94-
kind = data_kind(spec)
95-
if (kind == "file" and not is_nonstr_iter(spec)) or kind == "stringio":
96-
# Is a file but not a list of files or a SrtringIO object
92+
match data_kind(spec):
93+
case "vectors": # spec is None
94+
specfile = ""
95+
case kind if kind == "file" and not is_nonstr_iter(spec):
9796
specfile = spec
98-
else:
97+
case _:
9998
raise GMTInvalidInput(f"Unrecognized data type: {type(spec)}")
10099

101100
with Session() as lib:

0 commit comments

Comments
 (0)