Skip to content

Commit 38ac1b2

Browse files
authored
add a test
Add a test for the monotonicity of coordinates in the test_pcolorargs function.
1 parent ef8eaae commit 38ac1b2

File tree

1 file changed

+23
-1
lines changed

1 file changed

+23
-1
lines changed

lib/matplotlib/tests/test_axes.py

+23-1
Original file line numberDiff line numberDiff line change
@@ -1589,14 +1589,36 @@ def test_pcolorargs():
15891589
x = np.ma.array(x, mask=(x < 0))
15901590
with pytest.raises(ValueError):
15911591
ax.pcolormesh(x, y, Z[:-1, :-1])
1592-
# Expect a warning with non-increasing coordinates
1592+
# If the X or Y coords do not possess monotonicity in their respective
1593+
# directions, a warning indicating a bad grid will be triggered.
1594+
# The case of specifying coordinates by inputting 1D arrays.
15931595
x = [359, 0, 1]
15941596
y = [-10, 10]
15951597
X, Y = np.meshgrid(x, y)
15961598
Z = np.zeros(X.shape)
15971599
with pytest.warns(UserWarning,
15981600
match='are not monotonically increasing or decreasing'):
15991601
ax.pcolormesh(X, Y, Z, shading='auto')
1602+
# The case of specifying coordinates by inputting 2D arrays.
1603+
x = np.linspace(-1,1,3)
1604+
y = np.linspace(-1,1,3)
1605+
X, Y = np.meshgrid(x, y)
1606+
Z = np.zeros(X.shape)
1607+
np.random.seed(19680801)
1608+
noise_X = np.random.random(X.shape)
1609+
noise_Y = np.random.random(Y.shape)
1610+
with pytest.warns(UserWarning,
1611+
match='are not monotonically increasing or decreasing') as record:
1612+
# Small perturbations in coordinates will not disrupt the monotonicity
1613+
# of the X-coords and Y-coords in their respective directions.
1614+
# Therefore, no warnings will be triggered.
1615+
ax.pcolormesh(X+noise_X, Y+noise_Y, Z, shading='auto')
1616+
assert len(record) == 0
1617+
# Large perturbations have disrupted the monotonicity of the X-coords
1618+
# and Y-coords in their respective directions, thus resulting in two
1619+
# bad grid warnings.
1620+
ax.pcolormesh(X+10*noise_X, Y+10*noise_Y, Z, shading='auto')
1621+
assert len(record) == 2
16001622

16011623

16021624
def test_pcolormesh_underflow_error():

0 commit comments

Comments
 (0)