Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate Figure.subplot tests to dvc #1170

Merged
merged 5 commits into from
Apr 3, 2021
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
98 changes: 45 additions & 53 deletions pygmt/tests/test_subplot.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
autolabel=True,
margins=["0.3c", "0.1c"],
title="Subplot Title",
nrows=2,
ncols=1,
figsize=("15c", "6c"),
michaelgrund marked this conversation as resolved.
Show resolved Hide resolved
):
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"),
michaelgrund marked this conversation as resolved.
Show resolved Hide resolved
):
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():
Expand Down