Skip to content

Commit

Permalink
Allow for spaces in title and labels without needing double quotes
Browse files Browse the repository at this point in the history
Mitigates against GenericMappingTools#247.
  • Loading branch information
weiji14 committed Feb 6, 2021
1 parent dbd4677 commit 4126c16
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 7 deletions.
4 changes: 2 additions & 2 deletions examples/tutorials/subplots.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@
figsize=("15c", "6c"),
autolabel=True,
margins=["0.1c", "0.2c"],
title='"My Subplot Heading"',
title="My Subplot Heading",
):
fig.basemap(region=[0, 10, 0, 10], projection="X?", frame=["af", "WSne"], ax=[0, 0])
fig.basemap(region=[0, 20, 0, 10], projection="X?", frame=["af", "WSne"], ax=[0, 1])
Expand Down Expand Up @@ -155,7 +155,7 @@
figsize=("15c", "6c"),
autolabel=True,
margins=["0.3c", "0.2c"],
title='"My Subplot Heading"',
title="My Subplot Heading",
layout=["Rl", "Cb"],
frame="WSrt",
):
Expand Down
5 changes: 4 additions & 1 deletion pygmt/src/subplot.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,8 @@ def subplot(self, nrows=1, ncols=1, **kwargs):
{XY}
"""
kwargs = self._preprocess(**kwargs) # pylint: disable=protected-access
kwargs["A"] = f'"{kwargs.get("A")}"' if kwargs.get("A") else None
kwargs["T"] = f'"{kwargs.get("T")}"' if kwargs.get("T") else None

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

with Session() as lib:
arg_str = " ".join(["set", f"{ax}", build_arg_string(kwargs)])
arg_str = " ".join(["set", f"{ax}", build_arg_string(kwargs)]).strip()
lib.call_module(module="subplot", args=arg_str)
yield
8 changes: 4 additions & 4 deletions pygmt/tests/test_subplot.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ def test_subplot_basic_frame():
with fig_ref.sca(ax=1):
fig_ref.basemap(region=[0, 3, 0, 3], frame="+tplot1")
with fig_test.subplot(nrows=1, ncols=2, figsize=("6c", "3c"), frame="WSne"):
with fig_test.sca(ax=[0, 0]):
with fig_test.sca(ax="0,0"):
fig_test.basemap(region=[0, 3, 0, 3], frame="+tplot0")
with fig_test.sca(ax=[0, 1]):
with fig_test.sca(ax="0,1"):
fig_test.basemap(region=[0, 3, 0, 3], frame="+tplot1")
return fig_ref, fig_test

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

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

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

0 comments on commit 4126c16

Please sign in to comment.