Skip to content

Commit bcd0848

Browse files
committed
Figure.set_panel: Fix the bug when panel is not set
1 parent 2f61d38 commit bcd0848

2 files changed

Lines changed: 25 additions & 8 deletions

File tree

pygmt/src/subplot.py

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -419,13 +419,11 @@ def set_panel(
419419
aliasdict = AliasSystem(A=Alias(tag, name="tag")).add_common(V=verbose)
420420
aliasdict.merge(kwargs)
421421

422+
args = ["set"]
423+
if panel is not None:
424+
args.append(Alias(panel, name="panel", sep=",", size=2)._value)
425+
args.extend(build_arg_list(aliasdict))
426+
422427
with Session() as lib:
423-
lib.call_module(
424-
module="subplot",
425-
args=[
426-
"set",
427-
Alias(panel, name="panel", sep=",", size=2)._value,
428-
*build_arg_list(aliasdict),
429-
],
430-
)
428+
lib.call_module(module="subplot", args=args)
431429
yield

pygmt/tests/test_subplot.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,25 @@ def test_subplot_outside_plotting_positioning():
132132
return fig
133133

134134

135+
@pytest.mark.mpl_image_compare(filename="test_subplot_basic_frame.png")
136+
def test_subplot_set_panel_without_panel():
137+
"""
138+
Ensure Figure.set_panel works when panel is omitted.
139+
140+
Omitting ``panel`` should let GMT advance to the next panel according to the subplot
141+
order instead of passing an invalid ``None`` argument to the C API.
142+
143+
Use the baseline image from test_subplot_basic_frame.
144+
"""
145+
fig = Figure()
146+
with fig.subplot(nrows=1, ncols=2, figsize=("6c", "3c"), frame=Frame(axes="WSne")):
147+
with fig.set_panel():
148+
fig.basemap(region=[0, 3, 0, 3], frame=Frame(title="plot0"))
149+
with fig.set_panel():
150+
fig.basemap(region=[0, 3, 0, 3], frame=Frame(title="plot1"))
151+
return fig
152+
153+
135154
def test_subplot_deprecated_autolabel():
136155
"""
137156
Test that using the deprecated autolabel parameter raises a warning when conflicted

0 commit comments

Comments
 (0)