|
4 | 4 | import pytest
|
5 | 5 | from pygmt import Figure
|
6 | 6 | from pygmt.exceptions import GMTInvalidInput
|
7 |
| -from pygmt.helpers.testing import check_figures_equal |
8 | 7 |
|
9 | 8 |
|
10 |
| -@check_figures_equal() |
| 9 | +@pytest.mark.mpl_image_compare |
11 | 10 | def test_subplot_basic_frame():
|
12 | 11 | """
|
13 | 12 | Create a subplot figure with 1 vertical row and 2 horizontal columns, and
|
14 | 13 | ensure map frame setting is applied to all subplot figures.
|
15 | 14 | """
|
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 |
31 | 26 | def test_subplot_direct():
|
32 | 27 | """
|
33 | 28 | Plot map elements to subplot directly using the panel parameter.
|
34 | 29 | """
|
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() |
43 | 31 |
|
| 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 |
44 | 36 |
|
45 |
| -@check_figures_equal() |
| 37 | + |
| 38 | +@pytest.mark.mpl_image_compare |
46 | 39 | def test_subplot_autolabel_margins_title():
|
47 | 40 | """
|
48 | 41 | Make subplot figure with autolabels, setting some margins and a title.
|
49 | 42 | """
|
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() |
56 | 44 |
|
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", |
59 | 52 | ):
|
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]) |
62 | 55 |
|
63 |
| - return fig_ref, fig_test |
| 56 | + return fig |
64 | 57 |
|
65 | 58 |
|
66 |
| -@check_figures_equal() |
| 59 | +@pytest.mark.mpl_image_compare |
67 | 60 | def test_subplot_clearance_and_shared_xy_axis_layout():
|
68 | 61 | """
|
69 | 62 | Ensure subplot clearance works, and that the layout can be set to use
|
70 | 63 | shared X and Y axis labels across columns and rows.
|
71 | 64 | """
|
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() |
80 | 66 |
|
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, |
83 | 75 | ):
|
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) |
88 | 80 |
|
89 |
| - return fig_ref, fig_test |
| 81 | + return fig |
90 | 82 |
|
91 | 83 |
|
92 | 84 | def test_subplot_figsize_and_subsize_error():
|
|
0 commit comments