@@ -1589,14 +1589,36 @@ def test_pcolorargs():
1589
1589
x = np .ma .array (x , mask = (x < 0 ))
1590
1590
with pytest .raises (ValueError ):
1591
1591
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.
1593
1595
x = [359 , 0 , 1 ]
1594
1596
y = [- 10 , 10 ]
1595
1597
X , Y = np .meshgrid (x , y )
1596
1598
Z = np .zeros (X .shape )
1597
1599
with pytest .warns (UserWarning ,
1598
1600
match = 'are not monotonically increasing or decreasing' ):
1599
1601
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
1600
1622
1601
1623
1602
1624
def test_pcolormesh_underflow_error ():
0 commit comments