@@ -84,3 +84,46 @@ def test_pcolormesh_arg_interpolation():
8484 [2 , 20 ],
8585 [4 , 20 ]]])
8686 np .testing .assert_array_almost_equal (expected , coll ._coordinates )
87+
88+
89+ def test_pcolormesh_datalim ():
90+ # Test that wrapping the coordinates still produces proper data limits
91+ x = [359 , 1 , 3 ]
92+ y = [- 10 , 10 ]
93+
94+ xs , ys = np .meshgrid (x , y )
95+ # Z with the same shape as X/Y to force the interpolation
96+ z = np .zeros (xs .shape )
97+
98+ ax = plt .subplot (2 , 1 , 1 , projection = ccrs .PlateCarree ())
99+ coll = ax .pcolormesh (xs , ys , z , shading = 'auto' ,
100+ transform = ccrs .PlateCarree ())
101+
102+ coll_bbox = coll .get_datalim (ax .transData )
103+ np .testing .assert_array_equal (coll_bbox , [[- 2 , - 20 ], [4 , 20 ]])
104+
105+ # Non-wrapped coordinates
106+ x = [- 80 , 0 , 80 ]
107+ y = [- 10 , 10 ]
108+
109+ xs , ys = np .meshgrid (x , y )
110+ ax = plt .subplot (2 , 1 , 1 , projection = ccrs .PlateCarree ())
111+ coll = ax .pcolormesh (xs , ys , z , shading = 'auto' ,
112+ transform = ccrs .PlateCarree ())
113+
114+ coll_bbox = coll .get_datalim (ax .transData )
115+ np .testing .assert_array_equal (coll_bbox , [[- 120 , - 20 ], [120 , 20 ]])
116+
117+ # A projection that doesn't support wrapping
118+ x = [- 10 , 0 , 10 ]
119+ y = [- 10 , 10 ]
120+
121+ xs , ys = np .meshgrid (x , y )
122+ ax = plt .subplot (2 , 1 , 1 , projection = ccrs .Orthographic ())
123+ coll = ax .pcolormesh (xs , ys , z , shading = 'auto' ,
124+ transform = ccrs .PlateCarree ())
125+
126+ coll_bbox = coll .get_datalim (ax .transData )
127+ expected = [[- 1650783.327873 , - 2181451.330891 ],
128+ [1650783.327873 , 2181451.330891 ]]
129+ np .testing .assert_array_almost_equal (coll_bbox , expected )
0 commit comments