Skip to content

Commit 233b9aa

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 cd8ecc7 commit 233b9aa

File tree

4 files changed

+26
-11
lines changed

4 files changed

+26
-11
lines changed

pygmt/base_plotting.py

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ def _preprocess(self, **kwargs): # pylint: disable=no-self-use
6868
G="land",
6969
S="water",
7070
U="timestamp",
71+
c="ax",
7172
t="transparency",
7273
)
7374
@kwargs_to_strings(R="sequence")
@@ -146,6 +147,7 @@ def coast(self, **kwargs):
146147
F="box",
147148
G="truncate",
148149
W="scale",
150+
c="ax",
149151
t="transparency",
150152
)
151153
@kwargs_to_strings(R="sequence", G="sequence")
@@ -228,6 +230,7 @@ def colorbar(self, **kwargs):
228230
S="resample",
229231
U="timestamp",
230232
W="pen",
233+
c="ax",
231234
l="label",
232235
t="transparency",
233236
)
@@ -309,6 +312,7 @@ def grdcontour(self, grid, **kwargs):
309312
B="frame",
310313
I="shading",
311314
C="cmap",
315+
c="ax",
312316
t="transparency",
313317
)
314318
@kwargs_to_strings(R="sequence")
@@ -358,6 +362,7 @@ def grdimage(self, grid, **kwargs):
358362
Wf="facadepen",
359363
p="perspective",
360364
I="shading",
365+
c="ax",
361366
t="transparency",
362367
)
363368
@kwargs_to_strings(R="sequence", p="sequence")
@@ -476,6 +481,7 @@ def grdview(self, grid, **kwargs):
476481
l="label",
477482
C="cmap",
478483
U="timestamp",
484+
c="ax",
479485
t="transparency",
480486
)
481487
@kwargs_to_strings(R="sequence", i="sequence_comma")
@@ -597,6 +603,7 @@ def plot(self, x=None, y=None, data=None, sizes=None, direction=None, **kwargs):
597603
i="columns",
598604
l="label",
599605
C="levels",
606+
c="ax",
600607
t="transparency",
601608
)
602609
@kwargs_to_strings(R="sequence", i="sequence_comma")
@@ -686,6 +693,7 @@ def contour(self, x=None, y=None, z=None, data=None, **kwargs):
686693
Td="rose",
687694
Tm="compass",
688695
U="timestamp",
696+
c="ax",
689697
t="transparency",
690698
)
691699
@kwargs_to_strings(R="sequence")
@@ -736,6 +744,7 @@ def basemap(self, **kwargs):
736744
U="timestamp",
737745
D="position",
738746
F="box",
747+
c="ax",
739748
t="transparency",
740749
)
741750
@kwargs_to_strings(R="sequence")
@@ -779,6 +788,7 @@ def logo(self, **kwargs):
779788
D="position",
780789
F="box",
781790
M="monochrome",
791+
c="ax",
782792
t="transparency",
783793
)
784794
@kwargs_to_strings(R="sequence")
@@ -823,11 +833,7 @@ def image(self, imagefile, **kwargs):
823833

824834
@fmt_docstring
825835
@use_alias(
826-
R="region",
827-
J="projection",
828-
D="position",
829-
F="box",
830-
t="transparency",
836+
R="region", J="projection", D="position", F="box", c="ax", t="transparency"
831837
)
832838
@kwargs_to_strings(R="sequence")
833839
def legend(self, spec=None, position="JTR+jTR+o0.2c", box="+gwhite+p1p", **kwargs):
@@ -893,6 +899,7 @@ def legend(self, spec=None, position="JTR+jTR+o0.2c", box="+gwhite+p1p", **kwarg
893899
D="offset",
894900
G="fill",
895901
W="pen",
902+
c="ax",
896903
t="transparency",
897904
)
898905
@kwargs_to_strings(
@@ -1050,11 +1057,7 @@ def text(
10501057

10511058
@fmt_docstring
10521059
@use_alias(
1053-
R="region",
1054-
J="projection",
1055-
B="frame",
1056-
C="offset",
1057-
t="transparency",
1060+
R="region", J="projection", B="frame", C="offset", c="ax", t="transparency"
10581061
)
10591062
@kwargs_to_strings(R="sequence")
10601063
def meca(

pygmt/figure.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -430,7 +430,7 @@ def sca(self, ax=None, **kwargs):
430430
"""
431431
arg_str = " ".join(["set", f"{ax}", build_arg_string(kwargs)])
432432
with Session() as lib:
433-
lib.call_module(module=f"subplot", args=arg_str)
433+
lib.call_module(module="subplot", args=arg_str)
434434

435435
@fmt_docstring
436436
@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)