Skip to content

Commit c75a2ed

Browse files
Migrate Figure.subplot tests to dvc (#1170)
Co-authored-by: Wei Ji <[email protected]>
1 parent c05c975 commit c75a2ed

5 files changed

+61
-53
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
outs:
2+
- md5: 7be1b4ed2ec2eb506d9571e7ea3248ba
3+
size: 28164
4+
path: test_subplot_autolabel_margins_title.png
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
outs:
2+
- md5: 7149569679bfdef854f8683f30fc3cde
3+
size: 9251
4+
path: test_subplot_basic_frame.png
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
outs:
2+
- md5: 2a1b33433bd3921113938b8d7c0a4928
3+
size: 11245
4+
path: test_subplot_clearance_and_shared_xy_axis_layout.png
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
outs:
2+
- md5: d09053a8eaf8a4b32ec087f99004590b
3+
size: 13087
4+
path: test_subplot_direct.png

pygmt/tests/test_subplot.py

Lines changed: 45 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -4,89 +4,81 @@
44
import pytest
55
from pygmt import Figure
66
from pygmt.exceptions import GMTInvalidInput
7-
from pygmt.helpers.testing import check_figures_equal
87

98

10-
@check_figures_equal()
9+
@pytest.mark.mpl_image_compare
1110
def test_subplot_basic_frame():
1211
"""
1312
Create a subplot figure with 1 vertical row and 2 horizontal columns, and
1413
ensure map frame setting is applied to all subplot figures.
1514
"""
16-
fig_ref, fig_test = Figure(), Figure()
17-
with fig_ref.subplot(nrows=1, ncols=2, Ff="6c/3c", B="WSne"):
18-
with fig_ref.set_panel(panel=0):
19-
fig_ref.basemap(region=[0, 3, 0, 3], frame="+tplot0")
20-
with fig_ref.set_panel(panel=1):
21-
fig_ref.basemap(region=[0, 3, 0, 3], frame="+tplot1")
22-
with fig_test.subplot(nrows=1, ncols=2, figsize=("6c", "3c"), frame="WSne"):
23-
with fig_test.set_panel(panel="0,0"):
24-
fig_test.basemap(region=[0, 3, 0, 3], frame="+tplot0")
25-
with fig_test.set_panel(panel=[0, 1]):
26-
fig_test.basemap(region=[0, 3, 0, 3], frame="+tplot1")
27-
return fig_ref, fig_test
28-
29-
30-
@check_figures_equal()
15+
fig = Figure()
16+
17+
with fig.subplot(nrows=1, ncols=2, figsize=("6c", "3c"), frame="WSne"):
18+
with fig.set_panel(panel="0,0"):
19+
fig.basemap(region=[0, 3, 0, 3], frame="+tplot0")
20+
with fig.set_panel(panel=[0, 1]):
21+
fig.basemap(region=[0, 3, 0, 3], frame="+tplot1")
22+
return fig
23+
24+
25+
@pytest.mark.mpl_image_compare
3126
def test_subplot_direct():
3227
"""
3328
Plot map elements to subplot directly using the panel parameter.
3429
"""
35-
fig_ref, fig_test = Figure(), Figure()
36-
with fig_ref.subplot(nrows=2, ncols=1, Fs="3c/3c"):
37-
fig_ref.basemap(region=[0, 3, 0, 3], frame="af", panel=0)
38-
fig_ref.basemap(region=[0, 3, 0, 3], frame="af", panel=1)
39-
with fig_test.subplot(nrows=2, ncols=1, subsize=("3c", "3c")):
40-
fig_test.basemap(region=[0, 3, 0, 3], frame="af", panel=[0, 0])
41-
fig_test.basemap(region=[0, 3, 0, 3], frame="af", panel=[1, 0])
42-
return fig_ref, fig_test
30+
fig = Figure()
4331

32+
with fig.subplot(nrows=2, ncols=1, subsize=("3c", "3c")):
33+
fig.basemap(region=[0, 3, 0, 3], frame="af", panel=[0, 0])
34+
fig.basemap(region=[0, 3, 0, 3], frame="af", panel=[1, 0])
35+
return fig
4436

45-
@check_figures_equal()
37+
38+
@pytest.mark.mpl_image_compare
4639
def test_subplot_autolabel_margins_title():
4740
"""
4841
Make subplot figure with autolabels, setting some margins and a title.
4942
"""
50-
fig_ref, fig_test = Figure(), Figure()
51-
kwargs = dict(nrows=2, ncols=1, figsize=("15c", "6c"))
52-
53-
with fig_ref.subplot(A="a)", M="0.3c/0.1c", T="Subplot Title", **kwargs):
54-
fig_ref.basemap(region=[0, 1, 2, 3], frame="WSne", c="0,0")
55-
fig_ref.basemap(region=[4, 5, 6, 7], frame="WSne", c="1,0")
43+
fig = Figure()
5644

57-
with fig_test.subplot(
58-
autolabel=True, margins=["0.3c", "0.1c"], title="Subplot Title", **kwargs
45+
with fig.subplot(
46+
nrows=2,
47+
ncols=1,
48+
figsize=("15c", "6c"),
49+
autolabel=True,
50+
margins=["0.3c", "0.1c"],
51+
title="Subplot Title",
5952
):
60-
fig_test.basemap(region=[0, 1, 2, 3], frame="WSne", panel=[0, 0])
61-
fig_test.basemap(region=[4, 5, 6, 7], frame="WSne", panel=[1, 0])
53+
fig.basemap(region=[0, 1, 2, 3], frame="WSne", panel=[0, 0])
54+
fig.basemap(region=[4, 5, 6, 7], frame="WSne", panel=[1, 0])
6255

63-
return fig_ref, fig_test
56+
return fig
6457

6558

66-
@check_figures_equal()
59+
@pytest.mark.mpl_image_compare
6760
def test_subplot_clearance_and_shared_xy_axis_layout():
6861
"""
6962
Ensure subplot clearance works, and that the layout can be set to use
7063
shared X and Y axis labels across columns and rows.
7164
"""
72-
fig_ref, fig_test = Figure(), Figure()
73-
kwargs = dict(nrows=2, ncols=2, frame="WSrt", figsize=("5c", "5c"))
74-
75-
with fig_ref.subplot(C="y0.2c", SC="t", SR="", **kwargs):
76-
fig_ref.basemap(region=[0, 4, 0, 4], projection="X?", panel=True)
77-
fig_ref.basemap(region=[0, 8, 0, 4], projection="X?", panel=True)
78-
fig_ref.basemap(region=[0, 4, 0, 8], projection="X?", panel=True)
79-
fig_ref.basemap(region=[0, 8, 0, 8], projection="X?", panel=True)
65+
fig = Figure()
8066

81-
with fig_test.subplot(
82-
clearance=["s0.2c", "n0.2c"], sharex="t", sharey=True, **kwargs
67+
with fig.subplot(
68+
nrows=2,
69+
ncols=2,
70+
figsize=("5c", "5c"),
71+
frame="WSrt",
72+
clearance=["s0.2c", "n0.2c"],
73+
sharex="t",
74+
sharey=True,
8375
):
84-
fig_test.basemap(region=[0, 4, 0, 4], projection="X?", panel=True)
85-
fig_test.basemap(region=[0, 8, 0, 4], projection="X?", panel=True)
86-
fig_test.basemap(region=[0, 4, 0, 8], projection="X?", panel=True)
87-
fig_test.basemap(region=[0, 8, 0, 8], projection="X?", panel=True)
76+
fig.basemap(region=[0, 4, 0, 4], projection="X?", panel=True)
77+
fig.basemap(region=[0, 8, 0, 4], projection="X?", panel=True)
78+
fig.basemap(region=[0, 4, 0, 8], projection="X?", panel=True)
79+
fig.basemap(region=[0, 8, 0, 8], projection="X?", panel=True)
8880

89-
return fig_ref, fig_test
81+
return fig
9082

9183

9284
def test_subplot_figsize_and_subsize_error():

0 commit comments

Comments
 (0)