From 5fa9bfed2337d502bbafea504dba871ae8d0f144 Mon Sep 17 00:00:00 2001 From: Michael Grund <23025878+michaelgrund@users.noreply.github.com> Date: Sat, 3 Apr 2021 10:25:21 +0200 Subject: [PATCH 1/5] Migrate Figure.subplot tests to dvc Related to #1131. --- pygmt/tests/test_subplot.py | 22 +++++++++------------- 1 file changed, 9 insertions(+), 13 deletions(-) diff --git a/pygmt/tests/test_subplot.py b/pygmt/tests/test_subplot.py index 44d78a6aa9d..f27c71d1066 100644 --- a/pygmt/tests/test_subplot.py +++ b/pygmt/tests/test_subplot.py @@ -7,24 +7,20 @@ 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 + 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 @check_figures_equal() From 6ef57da4081c38143115773263beedf48af6a305 Mon Sep 17 00:00:00 2001 From: Michael Grund Date: Sat, 3 Apr 2021 10:54:17 +0200 Subject: [PATCH 2/5] replacements --- pygmt/tests/test_subplot.py | 72 ++++++++++++++++++------------------- 1 file changed, 34 insertions(+), 38 deletions(-) diff --git a/pygmt/tests/test_subplot.py b/pygmt/tests/test_subplot.py index f27c71d1066..d196b5f5a15 100644 --- a/pygmt/tests/test_subplot.py +++ b/pygmt/tests/test_subplot.py @@ -4,7 +4,6 @@ import pytest from pygmt import Figure from pygmt.exceptions import GMTInvalidInput -from pygmt.helpers.testing import check_figures_equal @pytest.mark.mpl_image_compare @@ -23,66 +22,63 @@ def test_subplot_basic_frame(): return fig -@check_figures_equal() +@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( + autolabel=True, + margins=["0.3c", "0.1c"], + title="Subplot Title", + nrows=2, + ncols=1, + figsize=("15c", "6c"), ): - 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( + clearance=["s0.2c", "n0.2c"], + sharex="t", + sharey=True, + nrows=2, + ncols=2, + frame="WSrt", + figsize=("5c", "5c"), ): - 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(): From dd49689cf6423fb6142f03118c741b41389f456c Mon Sep 17 00:00:00 2001 From: Michael Grund Date: Sat, 3 Apr 2021 10:56:43 +0200 Subject: [PATCH 3/5] add images to dvc --- .../baseline/test_subplot_autolabel_margins_title.png.dvc | 4 ++++ pygmt/tests/baseline/test_subplot_basic_frame.png.dvc | 4 ++++ .../test_subplot_clearance_and_shared_xy_axis_layout.png.dvc | 4 ++++ pygmt/tests/baseline/test_subplot_direct.png.dvc | 4 ++++ 4 files changed, 16 insertions(+) create mode 100644 pygmt/tests/baseline/test_subplot_autolabel_margins_title.png.dvc create mode 100644 pygmt/tests/baseline/test_subplot_basic_frame.png.dvc create mode 100644 pygmt/tests/baseline/test_subplot_clearance_and_shared_xy_axis_layout.png.dvc create mode 100644 pygmt/tests/baseline/test_subplot_direct.png.dvc 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 From af29c8c2ff701a81e8e1ba4acaf9e1ce0315a171 Mon Sep 17 00:00:00 2001 From: Michael Grund <23025878+michaelgrund@users.noreply.github.com> Date: Sat, 3 Apr 2021 11:09:51 +0200 Subject: [PATCH 4/5] Update pygmt/tests/test_subplot.py Co-authored-by: Wei Ji <23487320+weiji14@users.noreply.github.com> --- pygmt/tests/test_subplot.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pygmt/tests/test_subplot.py b/pygmt/tests/test_subplot.py index d196b5f5a15..5a5e78e6060 100644 --- a/pygmt/tests/test_subplot.py +++ b/pygmt/tests/test_subplot.py @@ -43,12 +43,12 @@ def test_subplot_autolabel_margins_title(): fig = Figure() with fig.subplot( - autolabel=True, - margins=["0.3c", "0.1c"], - title="Subplot Title", nrows=2, ncols=1, figsize=("15c", "6c"), + autolabel=True, + margins=["0.3c", "0.1c"], + title="Subplot Title", ): fig.basemap(region=[0, 1, 2, 3], frame="WSne", panel=[0, 0]) fig.basemap(region=[4, 5, 6, 7], frame="WSne", panel=[1, 0]) From 7513b6c050d6b233bc8ae523640adaf9f1dbbbad Mon Sep 17 00:00:00 2001 From: Michael Grund <23025878+michaelgrund@users.noreply.github.com> Date: Sat, 3 Apr 2021 11:09:58 +0200 Subject: [PATCH 5/5] Update pygmt/tests/test_subplot.py Co-authored-by: Wei Ji <23487320+weiji14@users.noreply.github.com> --- pygmt/tests/test_subplot.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/pygmt/tests/test_subplot.py b/pygmt/tests/test_subplot.py index 5a5e78e6060..2afd071391d 100644 --- a/pygmt/tests/test_subplot.py +++ b/pygmt/tests/test_subplot.py @@ -65,13 +65,13 @@ def test_subplot_clearance_and_shared_xy_axis_layout(): fig = Figure() with fig.subplot( - clearance=["s0.2c", "n0.2c"], - sharex="t", - sharey=True, nrows=2, ncols=2, - frame="WSrt", figsize=("5c", "5c"), + frame="WSrt", + clearance=["s0.2c", "n0.2c"], + sharex="t", + sharey=True, ): fig.basemap(region=[0, 4, 0, 4], projection="X?", panel=True) fig.basemap(region=[0, 8, 0, 4], projection="X?", panel=True)