Skip to content

Commit 3889f97

Browse files
committed
Alias ax (c) for subplot
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.
1 parent 0508310 commit 3889f97

File tree

4 files changed

+27
-7
lines changed

4 files changed

+27
-7
lines changed

pygmt/base_plotting.py

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ def _preprocess(self, **kwargs): # pylint: disable=no-self-use
7070
W="shorelines",
7171
G="land",
7272
S="water",
73+
c="ax",
7374
)
7475
@kwargs_to_strings(R="sequence")
7576
def coast(self, **kwargs):
@@ -146,6 +147,7 @@ def coast(self, **kwargs):
146147
F="box",
147148
G="truncate",
148149
W="scale",
150+
c="ax",
149151
)
150152
@kwargs_to_strings(R="sequence", G="sequence")
151153
def colorbar(self, **kwargs):
@@ -225,6 +227,7 @@ def colorbar(self, **kwargs):
225227
S="resample",
226228
U="logo",
227229
W="pen",
230+
c="ax",
228231
)
229232
@kwargs_to_strings(R="sequence", L="sequence", A="sequence_plus")
230233
def grdcontour(self, grid, **kwargs):
@@ -288,7 +291,9 @@ def grdcontour(self, grid, **kwargs):
288291
lib.call_module("grdcontour", arg_str)
289292

290293
@fmt_docstring
291-
@use_alias(R="region", J="projection", W="pen", B="frame", I="shading", C="cmap")
294+
@use_alias(
295+
R="region", J="projection", W="pen", B="frame", I="shading", C="cmap", c="ax"
296+
)
292297
@kwargs_to_strings(R="sequence")
293298
def grdimage(self, grid, **kwargs):
294299
"""
@@ -333,6 +338,7 @@ def grdimage(self, grid, **kwargs):
333338
Wc="contourpen",
334339
Wm="meshpen",
335340
Wf="facadepen",
341+
c="ax",
336342
p="perspective",
337343
)
338344
@kwargs_to_strings(R="sequence", p="sequence")
@@ -438,6 +444,7 @@ def grdview(self, grid, **kwargs):
438444
i="columns",
439445
l="label",
440446
C="cmap",
447+
c="ax",
441448
)
442449
@kwargs_to_strings(R="sequence", i="sequence_comma")
443450
def plot(self, x=None, y=None, data=None, sizes=None, direction=None, **kwargs):
@@ -555,6 +562,7 @@ def plot(self, x=None, y=None, data=None, sizes=None, direction=None, **kwargs):
555562
L="triangular_mesh_pen",
556563
i="columns",
557564
C="levels",
565+
c="ax",
558566
)
559567
@kwargs_to_strings(R="sequence", i="sequence_comma")
560568
def contour(self, x=None, y=None, z=None, data=None, **kwargs):
@@ -622,7 +630,7 @@ def contour(self, x=None, y=None, z=None, data=None, **kwargs):
622630
lib.call_module("contour", arg_str)
623631

624632
@fmt_docstring
625-
@use_alias(R="region", J="projection", B="frame")
633+
@use_alias(R="region", J="projection", B="frame", c="ax")
626634
@kwargs_to_strings(R="sequence")
627635
def basemap(self, **kwargs):
628636
"""
@@ -663,7 +671,7 @@ def basemap(self, **kwargs):
663671
lib.call_module("basemap", build_arg_string(kwargs))
664672

665673
@fmt_docstring
666-
@use_alias(R="region", J="projection")
674+
@use_alias(R="region", J="projection", c="ax")
667675
@kwargs_to_strings(R="sequence")
668676
def logo(self, **kwargs):
669677
"""
@@ -698,7 +706,7 @@ def logo(self, **kwargs):
698706
lib.call_module("logo", build_arg_string(kwargs))
699707

700708
@fmt_docstring
701-
@use_alias(R="region", J="projection")
709+
@use_alias(R="region", J="projection", c="ax")
702710
@kwargs_to_strings(R="sequence")
703711
def image(self, imagefile, **kwargs):
704712
"""
@@ -733,7 +741,7 @@ def image(self, imagefile, **kwargs):
733741
lib.call_module("image", arg_str)
734742

735743
@fmt_docstring
736-
@use_alias(R="region", J="projection", D="position", F="box")
744+
@use_alias(R="region", J="projection", D="position", F="box", c="ax")
737745
@kwargs_to_strings(R="sequence")
738746
def legend(self, spec=None, position="JTR+jTR+o0.2c", box="+gwhite+p1p", **kwargs):
739747
"""
@@ -788,7 +796,7 @@ def legend(self, spec=None, position="JTR+jTR+o0.2c", box="+gwhite+p1p", **kwarg
788796
lib.call_module("legend", arg_str)
789797

790798
@fmt_docstring
791-
@use_alias(R="region", J="projection", B="frame")
799+
@use_alias(R="region", J="projection", B="frame", c="ax")
792800
@kwargs_to_strings(
793801
R="sequence",
794802
textfiles="sequence_space",

pygmt/figure.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -421,7 +421,7 @@ def sca(self, ax=None, **kwargs):
421421
"""
422422
arg_str = " ".join(["set", f"{ax}", build_arg_string(kwargs)])
423423
with Session() as lib:
424-
lib.call_module(module=f"subplot", args=arg_str)
424+
lib.call_module(module="subplot", args=arg_str)
425425

426426
@fmt_docstring
427427
@use_alias(V="verbose")
11.2 KB
Loading

pygmt/tests/test_subplot.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,3 +32,15 @@ def test_subplot_frame():
3232
fig.basemap(region=[0, 3, 0, 3], frame="+tplot1")
3333
fig.end_subplot()
3434
return fig
35+
36+
37+
@pytest.mark.mpl_image_compare
38+
def test_subplot_direct():
39+
"""
40+
Plot map elements to subplots directly using ax argument
41+
"""
42+
fig, axs = subplots(nrows=2, ncols=1, figsize=("3c", "6c"))
43+
fig.basemap(region=[0, 3, 0, 3], frame=True, ax=axs[0, 0])
44+
fig.basemap(region=[0, 3, 0, 3], frame=True, ax=axs[1, 0])
45+
fig.end_subplot()
46+
return fig

0 commit comments

Comments
 (0)