Skip to content

Commit 4126c16

Browse files
committed
Allow for spaces in title and labels without needing double quotes
Mitigates against #247.
1 parent dbd4677 commit 4126c16

File tree

3 files changed

+10
-7
lines changed

3 files changed

+10
-7
lines changed

examples/tutorials/subplots.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@
9999
figsize=("15c", "6c"),
100100
autolabel=True,
101101
margins=["0.1c", "0.2c"],
102-
title='"My Subplot Heading"',
102+
title="My Subplot Heading",
103103
):
104104
fig.basemap(region=[0, 10, 0, 10], projection="X?", frame=["af", "WSne"], ax=[0, 0])
105105
fig.basemap(region=[0, 20, 0, 10], projection="X?", frame=["af", "WSne"], ax=[0, 1])
@@ -155,7 +155,7 @@
155155
figsize=("15c", "6c"),
156156
autolabel=True,
157157
margins=["0.3c", "0.2c"],
158-
title='"My Subplot Heading"',
158+
title="My Subplot Heading",
159159
layout=["Rl", "Cb"],
160160
frame="WSrt",
161161
):

pygmt/src/subplot.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,8 @@ def subplot(self, nrows=1, ncols=1, **kwargs):
135135
{XY}
136136
"""
137137
kwargs = self._preprocess(**kwargs) # pylint: disable=protected-access
138+
kwargs["A"] = f'"{kwargs.get("A")}"' if kwargs.get("A") else None
139+
kwargs["T"] = f'"{kwargs.get("T")}"' if kwargs.get("T") else None
138140

139141
with Session() as lib:
140142
try:
@@ -196,8 +198,9 @@ def sca(self, ax=None, **kwargs):
196198
{V}
197199
"""
198200
kwargs = self._preprocess(**kwargs) # pylint: disable=protected-access
201+
kwargs["A"] = f'"{kwargs.get("A")}"' if kwargs.get("A") else None
199202

200203
with Session() as lib:
201-
arg_str = " ".join(["set", f"{ax}", build_arg_string(kwargs)])
204+
arg_str = " ".join(["set", f"{ax}", build_arg_string(kwargs)]).strip()
202205
lib.call_module(module="subplot", args=arg_str)
203206
yield

pygmt/tests/test_subplot.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@ def test_subplot_basic_frame():
1818
with fig_ref.sca(ax=1):
1919
fig_ref.basemap(region=[0, 3, 0, 3], frame="+tplot1")
2020
with fig_test.subplot(nrows=1, ncols=2, figsize=("6c", "3c"), frame="WSne"):
21-
with fig_test.sca(ax=[0, 0]):
21+
with fig_test.sca(ax="0,0"):
2222
fig_test.basemap(region=[0, 3, 0, 3], frame="+tplot0")
23-
with fig_test.sca(ax=[0, 1]):
23+
with fig_test.sca(ax="0,1"):
2424
fig_test.basemap(region=[0, 3, 0, 3], frame="+tplot1")
2525
return fig_ref, fig_test
2626

@@ -48,12 +48,12 @@ def test_subplot_autolabel_margins_title():
4848
fig_ref, fig_test = Figure(), Figure()
4949
kwargs = dict(nrows=2, ncols=1, figsize=("15c", "6c"))
5050

51-
with fig_ref.subplot(A="(1)", M="0.3c/0.1c", T='"Subplot Title"', **kwargs):
51+
with fig_ref.subplot(A="(1)", M="0.3c/0.1c", T="Subplot Title", **kwargs):
5252
fig_ref.basemap(region=[0, 1, 2, 3], frame="WSne", c="0,0")
5353
fig_ref.basemap(region=[4, 5, 6, 7], frame="WSne", c="1,0")
5454

5555
with fig_test.subplot(
56-
autolabel="(1)", margins=["0.3c", "0.1c"], title='"Subplot Title"', **kwargs
56+
autolabel="(1)", margins=["0.3c", "0.1c"], title="Subplot Title", **kwargs
5757
):
5858
fig_test.basemap(region=[0, 1, 2, 3], frame="WSne", ax=[0, 0])
5959
fig_test.basemap(region=[4, 5, 6, 7], frame="WSne", ax=[1, 0])

0 commit comments

Comments
 (0)