def test_shared():
    rdim = (4, 4, 2)
    share = {
        'all': numpy.ones(rdim[:2], dtype=bool),
        'none': numpy.zeros(rdim[:2], dtype=bool),
        'row': numpy.array([
            [False, True, False, False],
            [True, False, False, False],
            [False, False, False, True],
            [False, False, True, False]]),
        'col': numpy.array([
            [False, False, True, False],
            [False, False, False, True],
            [True, False, False, False],
            [False, True, False, False]]),
        }
    visible = {
        'x': {
            'all': [False, False, True, True],
            'col': [False, False, True, True],
            'row': [True] * 4,
            'none': [True] * 4,
            False: [True] * 4,
            True: [False, False, True, True],
            },
        'y': {
            'all': [True, False, True, False],
            'col': [True] * 4,
            'row': [True, False, True, False],
            'none': [True] * 4,
            False: [True] * 4,
            True: [True, False, True, False],
            },
        }
    share[False] = share['none']
    share[True] = share['all']

    # test default
    axs = [axis for axis, _ in zip(plt.subplots_iterator(2, 2), range(4))]
    check_shared(axs, share['none'], share['none'])
    plt.close(axs[0].figure)

    # test all option combinations
    ops = [False, True, 'all', 'none', 'row', 'col']
    for xo in ops:
        for yo in ops:
            axs = [axis for axis, _ in zip(plt.subplots_iterator(2, 2, sharex=xo, sharey=yo), range(4))]
            check_shared(axs, share[xo], share[yo])
            check_visible(axs, visible['x'][xo], visible['y'][yo])
            plt.close(axs[0].figure)

    # test label_outer
    axs = [axis for axis, _ in zip(plt.subplots_iterator(2, 2, sharex=True, sharey=True), range(4))]
    for ax in axs:
        ax.label_outer()
    check_visible(axs, [False, False, True, True], [True, False, True, False])
def test_exceptions():
    # TODO should this test more options?
    assert_raises(ValueError, lambda: next(plt.subplots_iterator(2, 2, sharex='blah')) )
    assert_raises(ValueError, lambda: next(plt.subplots_iterator(2, 2, sharey='blah')) )
    # We filter warnings in this test which are genuine since
    # the point of this test is to ensure that this raises.
    with warnings.catch_warnings():
        warnings.filterwarnings('ignore',
                                message='.*sharex\ argument\ to\ subplots',
                                category=UserWarning)
        assert_raises(ValueError, lambda: next(plt.subplots_iterator(2, 2, sharex=-1)) )
        assert_raises(ValueError, lambda: next(plt.subplots_iterator(2, 2, sharex=0))  )
        assert_raises(ValueError, lambda: next(plt.subplots_iterator(2, 2, sharex=5))  )
def test_subplots_offsettext():
    x = numpy.arange(0, 1e10, 1e9)
    y = numpy.arange(0, 100, 10)+1e4
    it = plt.subplots_iterator(2, 2, sharex='col', sharey='all')
    next(it).plot(x, x)
    next(it).plot(y, x)
    next(it).plot(x, x)
    next(it).plot(y, x)
def test_multiple_figures():
    x = numpy.arange(0, 1e10, 1e9)
    y = numpy.arange(0, 100, 10)+1e4
    it = plt.subplots_iterator(2, 2, sharex='col', sharey='all')
    for _ in range(12):
        next(it).plot(x, y)