def test_layout(): "Test the Layout class" for nax in range(1, 100): assert_layout_ok(nax, 1.5, 2, True, w=5) assert_layout_ok(nax, 1.5, 2, True, h=5) assert_layout_ok(nax, 1.5, 2, True, axw=5) assert_layout_ok(nax, 1.5, 2, True, axh=5) assert_layout_ok(nax, 1.5, 2, True, axw=5, w=20) assert_layout_ok(nax, 1.5, 2, True, axw=5, h=20) assert_layout_ok(nax, 1.5, 2, True, axh=5, w=20) assert_layout_ok(nax, 1.5, 2, True, axh=5, h=20) # single axes larger than figure with pytest.raises(ValueError): Layout(2, 1.5, 2, True, h=5, axh=6) with pytest.raises(ValueError): Layout(2, 1.5, 2, True, w=5, axw=6) # left margin & axw margins = dict(left=1, top=2, bottom=1, wspace=1, hspace=2) layout = Layout(2, 2, 2, margins=margins, axw=5, w=10, ncol=1) assert layout.w == 10 assert layout.margins == dict(right=10 - 1 - 5, **margins) assert layout.axh == 2.5 assert layout.h == 5 + 2 * layout.axh assert layout.tight is False layout = Layout(2, 2, 2, margins=True, axw=5, w=10, ncol=1) assert layout.tight is False
def assert_layout_ok(*args, **kwargs): error = None l = Layout(*args, **kwargs) if l.nrow * l.ncol < l.nax: error = ("%i rows * %i cols = %i < %i (nax). args=%%r, kwargs=%%r" % (l.nrow, l.ncol, l.nrow * l.ncol, l.nax)) if error: raise AssertionError(error % (args, kwargs))
def assert_layout_ok(*args, **kwargs): layout = Layout(*args, **kwargs) assert layout.nrow * layout.ncol >= layout.nax