Skip to content

Commit

Permalink
Alias ax (c) for subplot
Browse files Browse the repository at this point in the history
Used to advance to the selected subplot panel. Technically only allowed when in subplot mode. See https://docs.generic-mapping-tools.org/latest/gmt.html#c-full.
  • Loading branch information
weiji14 committed Sep 20, 2020
1 parent cd8ecc7 commit 233b9aa
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 11 deletions.
23 changes: 13 additions & 10 deletions pygmt/base_plotting.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ def _preprocess(self, **kwargs): # pylint: disable=no-self-use
G="land",
S="water",
U="timestamp",
c="ax",
t="transparency",
)
@kwargs_to_strings(R="sequence")
Expand Down Expand Up @@ -146,6 +147,7 @@ def coast(self, **kwargs):
F="box",
G="truncate",
W="scale",
c="ax",
t="transparency",
)
@kwargs_to_strings(R="sequence", G="sequence")
Expand Down Expand Up @@ -228,6 +230,7 @@ def colorbar(self, **kwargs):
S="resample",
U="timestamp",
W="pen",
c="ax",
l="label",
t="transparency",
)
Expand Down Expand Up @@ -309,6 +312,7 @@ def grdcontour(self, grid, **kwargs):
B="frame",
I="shading",
C="cmap",
c="ax",
t="transparency",
)
@kwargs_to_strings(R="sequence")
Expand Down Expand Up @@ -358,6 +362,7 @@ def grdimage(self, grid, **kwargs):
Wf="facadepen",
p="perspective",
I="shading",
c="ax",
t="transparency",
)
@kwargs_to_strings(R="sequence", p="sequence")
Expand Down Expand Up @@ -476,6 +481,7 @@ def grdview(self, grid, **kwargs):
l="label",
C="cmap",
U="timestamp",
c="ax",
t="transparency",
)
@kwargs_to_strings(R="sequence", i="sequence_comma")
Expand Down Expand Up @@ -597,6 +603,7 @@ def plot(self, x=None, y=None, data=None, sizes=None, direction=None, **kwargs):
i="columns",
l="label",
C="levels",
c="ax",
t="transparency",
)
@kwargs_to_strings(R="sequence", i="sequence_comma")
Expand Down Expand Up @@ -686,6 +693,7 @@ def contour(self, x=None, y=None, z=None, data=None, **kwargs):
Td="rose",
Tm="compass",
U="timestamp",
c="ax",
t="transparency",
)
@kwargs_to_strings(R="sequence")
Expand Down Expand Up @@ -736,6 +744,7 @@ def basemap(self, **kwargs):
U="timestamp",
D="position",
F="box",
c="ax",
t="transparency",
)
@kwargs_to_strings(R="sequence")
Expand Down Expand Up @@ -779,6 +788,7 @@ def logo(self, **kwargs):
D="position",
F="box",
M="monochrome",
c="ax",
t="transparency",
)
@kwargs_to_strings(R="sequence")
Expand Down Expand Up @@ -823,11 +833,7 @@ def image(self, imagefile, **kwargs):

@fmt_docstring
@use_alias(
R="region",
J="projection",
D="position",
F="box",
t="transparency",
R="region", J="projection", D="position", F="box", c="ax", t="transparency"
)
@kwargs_to_strings(R="sequence")
def legend(self, spec=None, position="JTR+jTR+o0.2c", box="+gwhite+p1p", **kwargs):
Expand Down Expand Up @@ -893,6 +899,7 @@ def legend(self, spec=None, position="JTR+jTR+o0.2c", box="+gwhite+p1p", **kwarg
D="offset",
G="fill",
W="pen",
c="ax",
t="transparency",
)
@kwargs_to_strings(
Expand Down Expand Up @@ -1050,11 +1057,7 @@ def text(

@fmt_docstring
@use_alias(
R="region",
J="projection",
B="frame",
C="offset",
t="transparency",
R="region", J="projection", B="frame", C="offset", c="ax", t="transparency"
)
@kwargs_to_strings(R="sequence")
def meca(
Expand Down
2 changes: 1 addition & 1 deletion pygmt/figure.py
Original file line number Diff line number Diff line change
Expand Up @@ -430,7 +430,7 @@ def sca(self, ax=None, **kwargs):
"""
arg_str = " ".join(["set", f"{ax}", build_arg_string(kwargs)])
with Session() as lib:
lib.call_module(module=f"subplot", args=arg_str)
lib.call_module(module="subplot", args=arg_str)

@fmt_docstring
@use_alias(V="verbose")
Expand Down
Binary file added pygmt/tests/baseline/test_subplot_direct.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
12 changes: 12 additions & 0 deletions pygmt/tests/test_subplot.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,15 @@ def test_subplot_frame():
fig.basemap(region=[0, 3, 0, 3], frame="+tplot1")
fig.end_subplot()
return fig


@pytest.mark.mpl_image_compare
def test_subplot_direct():
"""
Plot map elements to subplots directly using ax argument
"""
fig, axs = subplots(nrows=2, ncols=1, figsize=("3c", "6c"))
fig.basemap(region=[0, 3, 0, 3], frame=True, ax=axs[0, 0])
fig.basemap(region=[0, 3, 0, 3], frame=True, ax=axs[1, 0])
fig.end_subplot()
return fig

0 comments on commit 233b9aa

Please sign in to comment.