Skip to content

Commit 90455c1

Browse files
committed
Merge remote-tracking branch 'origin/refactor/legend' into api/virtualfile-from-stringio
2 parents c589a40 + ff90b2e commit 90455c1

File tree

2 files changed

+9
-8
lines changed

2 files changed

+9
-8
lines changed

pygmt/src/legend.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ def legend(
5454
spec
5555
The legend specification. It can be:
5656
57-
- ``None`` for using the automatically generated legend specification file.
57+
- ``None`` means using the automatically generated legend specification file.
5858
- A string or a :class:`pathlib.PurePath` object pointing to the legend
5959
specification file.
6060
- A :class:`io.StringIO` object containing the legend specification.
@@ -90,7 +90,7 @@ def legend(
9090
kwargs["F"] = box
9191

9292
kind = data_kind(spec)
93-
if kind not in {"vectors", "file", "stringio"}:
93+
if kind not in {"vectors", "file", "stringio"}: # kind="vectors" means spec is None
9494
raise GMTInvalidInput(f"Unrecognized data type: {type(spec)}")
9595
if kind == "file" and is_nonstr_iter(spec):
9696
raise GMTInvalidInput("Only one legend specification file is allowed.")

pygmt/tests/test_legend.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
@pytest.fixture(scope="module", name="legend_spec")
1515
def fixture_legend_spec():
1616
"""
17-
Return a legend specification file content.
17+
A string contains a legend specification.
1818
"""
1919
return """
2020
G -0.1i
@@ -47,7 +47,7 @@ def fixture_legend_spec():
4747
@pytest.mark.mpl_image_compare
4848
def test_legend_position():
4949
"""
50-
Test that plots a position with each of the four legend coordinate systems.
50+
Test positioning the legend with different coordinate systems.
5151
"""
5252
fig = Figure()
5353
fig.basemap(region=[-2, 2, -2, 2], frame=True)
@@ -74,7 +74,7 @@ def test_legend_default_position():
7474
@pytest.mark.mpl_image_compare
7575
def test_legend_entries():
7676
"""
77-
Test different marker types/shapes.
77+
Test legend using the automatically generated legend entries.
7878
"""
7979
fig = Figure()
8080
fig.basemap(projection="x1i", region=[0, 7, 3, 7], frame=True)
@@ -98,11 +98,9 @@ def test_legend_specfile(legend_spec):
9898
"""
9999
with GMTTempFile() as specfile:
100100
Path(specfile.name).write_text(legend_spec, encoding="utf-8")
101-
spec = specfile.name
102-
103101
fig = Figure()
104102
fig.basemap(projection="x6i", region=[0, 1, 0, 1], frame=True)
105-
fig.legend(spec, position="JTM+jCM+w5i")
103+
fig.legend(specfile.name, position="JTM+jCM+w5i")
106104
return fig
107105

108106

@@ -125,3 +123,6 @@ def test_legend_fails():
125123
fig = Figure()
126124
with pytest.raises(GMTInvalidInput):
127125
fig.legend(spec=["@Table_5_11.txt"])
126+
127+
with pytest.raises(GMTInvalidInput):
128+
fig.legend(spec=[1, 2])

0 commit comments

Comments
 (0)