Repository: matplotlib/matplotlib
File: lib/matplotlib/tests/test_collections.py (Python)

Code before:
        c.set_array("wrong_input")

    # Test if array kwarg is copied
    vals[5] = 45
    assert np.not_equal(vals, c.get_array()).any()


def test_blended_collection_autolim():
    f, ax = plt.subplots()

    # sample data to give initial data limits
    ax.plot([2, 3, 4], [0.4, 0.6, 0.5])
    np.testing.assert_allclose((ax.dataLim.xmin, ax.dataLim.xmax), (2, 4))
    data_ymin, data_ymax = ax.dataLim.ymin, ax.dataLim.ymax

    # LineCollection with vertical lines spanning the Axes vertical, using transAxes
    x = [1, 2, 3, 4, 5]
    vertical_lines = [np.array([[xi, 0], [xi, 1]]) for xi in x]
    trans = mtransforms.blended_transform_factory(ax.transData, ax.transAxes)
    ax.add_collection(LineCollection(vertical_lines, transform=trans))

    # check that the x data limits are updated to include the LineCollection
    np.testing.assert_allclose((ax.dataLim.xmin, ax.dataLim.xmax), (1, 5))
    # check that the y data limits are not updated (because they are not transData)
    np.testing.assert_allclose((ax.dataLim.ymin, ax.dataLim.ymax), (0.4, 0.6))


def test_singleton_autolim():
    fig, ax = plt.subplots()
    ax.scatter(0, 0)
    np.testing.assert_allclose(ax.get_ylim(), [-0.06, 0.06])
    np.testing.assert_allclose(ax.get_xlim(), [-0.06, 0.06])


@pytest.mark.parametrize("transform, expected", [
    ("transData", (-0.5, 3.5)),
    ("transAxes", (2.8, 3.2)),
])
def test_autolim_with_zeros(transform, expected):
    # 1) Test that a scatter at (0, 0) data coordinates contributes to
    # autoscaling even though any(offsets) would be False in that situation.
    # 2) Test that specifying transAxes for the transform does not contribute
    # to the autoscaling.
    fig, ax = plt.subplots()
    ax.scatter(0, 0, transform=getattr(ax, transform))
    ax.scatter(3, 3)
    np.testing.assert_allclose(ax.get_ylim(), expected)
    np.testing.assert_allclose(ax.get_xlim(), expected)


def test_quadmesh_set_array_validation(pcfunc):

Review comment (suggestion):
```suggestion
    np.testing.assert_allclose((ax.dataLim.ymin, ax.dataLim.ymax), (data_ymin, data_ymax))
```
Otherwise `data_ymin, data_ymax` are unused and should be removed.

Code after:
        c.set_array("wrong_input")

    # Test if array kwarg is copied
    vals[5] = 45
    assert np.not_equal(vals, c.get_array()).any()


def test_blended_collection_autolim():
    f, ax = plt.subplots()

    # sample data to give initial data limits
    ax.plot([2, 3, 4], [0.4, 0.6, 0.5])
    np.testing.assert_allclose((ax.dataLim.xmin, ax.dataLim.xmax), (2, 4))
    data_ymin, data_ymax = ax.dataLim.ymin, ax.dataLim.ymax

    # LineCollection with vertical lines spanning the Axes vertical, using transAxes
    x = [1, 2, 3, 4, 5]
    vertical_lines = [np.array([[xi, 0], [xi, 1]]) for xi in x]
    trans = mtransforms.blended_transform_factory(ax.transData, ax.transAxes)
    ax.add_collection(LineCollection(vertical_lines, transform=trans))

    # check that the x data limits are updated to include the LineCollection
    np.testing.assert_allclose((ax.dataLim.xmin, ax.dataLim.xmax), (1, 5))
    # check that the y data limits are not updated (because they are not transData)
    np.testing.assert_allclose((ax.dataLim.ymin, ax.dataLim.ymax),
                               (data_ymin, data_ymax))


def test_singleton_autolim():
    fig, ax = plt.subplots()
    ax.scatter(0, 0)
    np.testing.assert_allclose(ax.get_ylim(), [-0.06, 0.06])
    np.testing.assert_allclose(ax.get_xlim(), [-0.06, 0.06])


@pytest.mark.parametrize("transform, expected", [
    ("transData", (-0.5, 3.5)),
    ("transAxes", (2.8, 3.2)),
])
def test_autolim_with_zeros(transform, expected):
    # 1) Test that a scatter at (0, 0) data coordinates contributes to
    # autoscaling even though any(offsets) would be False in that situation.
    # 2) Test that specifying transAxes for the transform does not contribute
    # to the autoscaling.
    fig, ax = plt.subplots()
    ax.scatter(0, 0, transform=getattr(ax, transform))
    ax.scatter(3, 3)
    np.testing.assert_allclose(ax.get_ylim(), expected)
    np.testing.assert_allclose(ax.get_xlim(), expected)