diff --git a/pygmt/tests/baseline/test_subplot_autolabel_margins_title.png.dvc b/pygmt/tests/baseline/test_subplot_autolabel_margins_title.png.dvc new file mode 100644 index 00000000000..644df7c2b59 --- /dev/null +++ b/pygmt/tests/baseline/test_subplot_autolabel_margins_title.png.dvc @@ -0,0 +1,4 @@ +outs: +- md5: 7be1b4ed2ec2eb506d9571e7ea3248ba + size: 28164 + path: test_subplot_autolabel_margins_title.png diff --git a/pygmt/tests/baseline/test_subplot_basic_frame.png.dvc b/pygmt/tests/baseline/test_subplot_basic_frame.png.dvc new file mode 100644 index 00000000000..83ee19173ae --- /dev/null +++ b/pygmt/tests/baseline/test_subplot_basic_frame.png.dvc @@ -0,0 +1,4 @@ +outs: +- md5: 7149569679bfdef854f8683f30fc3cde + size: 9251 + path: test_subplot_basic_frame.png diff --git a/pygmt/tests/baseline/test_subplot_clearance_and_shared_xy_axis_layout.png.dvc b/pygmt/tests/baseline/test_subplot_clearance_and_shared_xy_axis_layout.png.dvc new file mode 100644 index 00000000000..65b418fed55 --- /dev/null +++ b/pygmt/tests/baseline/test_subplot_clearance_and_shared_xy_axis_layout.png.dvc @@ -0,0 +1,4 @@ +outs: +- md5: 2a1b33433bd3921113938b8d7c0a4928 + size: 11245 + path: test_subplot_clearance_and_shared_xy_axis_layout.png diff --git a/pygmt/tests/baseline/test_subplot_direct.png.dvc b/pygmt/tests/baseline/test_subplot_direct.png.dvc new file mode 100644 index 00000000000..d9256e41a44 --- /dev/null +++ b/pygmt/tests/baseline/test_subplot_direct.png.dvc @@ -0,0 +1,4 @@ +outs: +- md5: d09053a8eaf8a4b32ec087f99004590b + size: 13087 + path: test_subplot_direct.png diff --git a/pygmt/tests/test_subplot.py b/pygmt/tests/test_subplot.py index 44d78a6aa9d..2afd071391d 100644 --- a/pygmt/tests/test_subplot.py +++ b/pygmt/tests/test_subplot.py @@ -4,89 +4,81 @@ import pytest from pygmt import Figure from pygmt.exceptions import GMTInvalidInput -from pygmt.helpers.testing import check_figures_equal -@check_figures_equal() +@pytest.mark.mpl_image_compare def test_subplot_basic_frame(): """ Create a subplot figure with 1 vertical row and 2 horizontal columns, and ensure map frame setting is applied to all subplot figures. """ - fig_ref, fig_test = Figure(), Figure() - with fig_ref.subplot(nrows=1, ncols=2, Ff="6c/3c", B="WSne"): - with fig_ref.set_panel(panel=0): - fig_ref.basemap(region=[0, 3, 0, 3], frame="+tplot0") - with fig_ref.set_panel(panel=1): - fig_ref.basemap(region=[0, 3, 0, 3], frame="+tplot1") - with fig_test.subplot(nrows=1, ncols=2, figsize=("6c", "3c"), frame="WSne"): - with fig_test.set_panel(panel="0,0"): - fig_test.basemap(region=[0, 3, 0, 3], frame="+tplot0") - with fig_test.set_panel(panel=[0, 1]): - fig_test.basemap(region=[0, 3, 0, 3], frame="+tplot1") - return fig_ref, fig_test - - -@check_figures_equal() + fig = Figure() + + with fig.subplot(nrows=1, ncols=2, figsize=("6c", "3c"), frame="WSne"): + with fig.set_panel(panel="0,0"): + fig.basemap(region=[0, 3, 0, 3], frame="+tplot0") + with fig.set_panel(panel=[0, 1]): + fig.basemap(region=[0, 3, 0, 3], frame="+tplot1") + return fig + + +@pytest.mark.mpl_image_compare def test_subplot_direct(): """ Plot map elements to subplot directly using the panel parameter. """ - fig_ref, fig_test = Figure(), Figure() - with fig_ref.subplot(nrows=2, ncols=1, Fs="3c/3c"): - fig_ref.basemap(region=[0, 3, 0, 3], frame="af", panel=0) - fig_ref.basemap(region=[0, 3, 0, 3], frame="af", panel=1) - with fig_test.subplot(nrows=2, ncols=1, subsize=("3c", "3c")): - fig_test.basemap(region=[0, 3, 0, 3], frame="af", panel=[0, 0]) - fig_test.basemap(region=[0, 3, 0, 3], frame="af", panel=[1, 0]) - return fig_ref, fig_test + fig = Figure() + with fig.subplot(nrows=2, ncols=1, subsize=("3c", "3c")): + fig.basemap(region=[0, 3, 0, 3], frame="af", panel=[0, 0]) + fig.basemap(region=[0, 3, 0, 3], frame="af", panel=[1, 0]) + return fig -@check_figures_equal() + +@pytest.mark.mpl_image_compare def test_subplot_autolabel_margins_title(): """ Make subplot figure with autolabels, setting some margins and a title. """ - fig_ref, fig_test = Figure(), Figure() - kwargs = dict(nrows=2, ncols=1, figsize=("15c", "6c")) - - with fig_ref.subplot(A="a)", M="0.3c/0.1c", T="Subplot Title", **kwargs): - fig_ref.basemap(region=[0, 1, 2, 3], frame="WSne", c="0,0") - fig_ref.basemap(region=[4, 5, 6, 7], frame="WSne", c="1,0") + fig = Figure() - with fig_test.subplot( - autolabel=True, margins=["0.3c", "0.1c"], title="Subplot Title", **kwargs + with fig.subplot( + nrows=2, + ncols=1, + figsize=("15c", "6c"), + autolabel=True, + margins=["0.3c", "0.1c"], + title="Subplot Title", ): - fig_test.basemap(region=[0, 1, 2, 3], frame="WSne", panel=[0, 0]) - fig_test.basemap(region=[4, 5, 6, 7], frame="WSne", panel=[1, 0]) + fig.basemap(region=[0, 1, 2, 3], frame="WSne", panel=[0, 0]) + fig.basemap(region=[4, 5, 6, 7], frame="WSne", panel=[1, 0]) - return fig_ref, fig_test + return fig -@check_figures_equal() +@pytest.mark.mpl_image_compare def test_subplot_clearance_and_shared_xy_axis_layout(): """ Ensure subplot clearance works, and that the layout can be set to use shared X and Y axis labels across columns and rows. """ - fig_ref, fig_test = Figure(), Figure() - kwargs = dict(nrows=2, ncols=2, frame="WSrt", figsize=("5c", "5c")) - - with fig_ref.subplot(C="y0.2c", SC="t", SR="", **kwargs): - fig_ref.basemap(region=[0, 4, 0, 4], projection="X?", panel=True) - fig_ref.basemap(region=[0, 8, 0, 4], projection="X?", panel=True) - fig_ref.basemap(region=[0, 4, 0, 8], projection="X?", panel=True) - fig_ref.basemap(region=[0, 8, 0, 8], projection="X?", panel=True) + fig = Figure() - with fig_test.subplot( - clearance=["s0.2c", "n0.2c"], sharex="t", sharey=True, **kwargs + with fig.subplot( + nrows=2, + ncols=2, + figsize=("5c", "5c"), + frame="WSrt", + clearance=["s0.2c", "n0.2c"], + sharex="t", + sharey=True, ): - fig_test.basemap(region=[0, 4, 0, 4], projection="X?", panel=True) - fig_test.basemap(region=[0, 8, 0, 4], projection="X?", panel=True) - fig_test.basemap(region=[0, 4, 0, 8], projection="X?", panel=True) - fig_test.basemap(region=[0, 8, 0, 8], projection="X?", panel=True) + fig.basemap(region=[0, 4, 0, 4], projection="X?", panel=True) + fig.basemap(region=[0, 8, 0, 4], projection="X?", panel=True) + fig.basemap(region=[0, 4, 0, 8], projection="X?", panel=True) + fig.basemap(region=[0, 8, 0, 8], projection="X?", panel=True) - return fig_ref, fig_test + return fig def test_subplot_figsize_and_subsize_error():