@@ -1341,3 +1341,69 @@ def test_triplot_label():
1341
1341
assert labels == ['label' ]
1342
1342
assert len (handles ) == 1
1343
1343
assert handles [0 ] is lines
1344
+
1345
+
1346
+ def test_tricontour_path ():
1347
+ x = [0 , 4 , 4 , 0 , 2 ]
1348
+ y = [0 , 0 , 4 , 4 , 2 ]
1349
+ triang = mtri .Triangulation (x , y )
1350
+ _ , ax = plt .subplots ()
1351
+
1352
+ # Line strip from boundary to boundary
1353
+ cs = ax .tricontour (triang , [1 , 0 , 0 , 0 , 0 ], levels = [0.5 ])
1354
+ assert len (cs .collections ) == 1
1355
+ paths = cs .collections [0 ].get_paths ()
1356
+ assert len (paths ) == 1
1357
+ expected_vertices = [[2 , 0 ], [1 , 1 ], [0 , 2 ]]
1358
+ assert_array_almost_equal (paths [0 ].vertices , expected_vertices )
1359
+ assert_array_equal (paths [0 ].codes , [1 , 2 , 2 ])
1360
+ assert_array_almost_equal (
1361
+ paths [0 ].to_polygons (closed_only = False ), [expected_vertices ])
1362
+
1363
+ # Closed line loop inside domain
1364
+ cs = ax .tricontour (triang , [0 , 0 , 0 , 0 , 1 ], levels = [0.5 ])
1365
+ assert len (cs .collections ) == 1
1366
+ paths = cs .collections [0 ].get_paths ()
1367
+ assert len (paths ) == 1
1368
+ expected_vertices = [[3 , 1 ], [3 , 3 ], [1 , 3 ], [1 , 1 ], [3 , 1 ]]
1369
+ assert_array_almost_equal (paths [0 ].vertices , expected_vertices )
1370
+ assert_array_equal (paths [0 ].codes , [1 , 2 , 2 , 2 , 79 ])
1371
+ assert_array_almost_equal (paths [0 ].to_polygons (), [expected_vertices ])
1372
+
1373
+
1374
+ def test_tricontourf_path ():
1375
+ x = [0 , 4 , 4 , 0 , 2 ]
1376
+ y = [0 , 0 , 4 , 4 , 2 ]
1377
+ triang = mtri .Triangulation (x , y )
1378
+ _ , ax = plt .subplots ()
1379
+
1380
+ # Polygon inside domain
1381
+ cs = ax .tricontourf (triang , [0 , 0 , 0 , 0 , 1 ], levels = [0.5 , 1.5 ])
1382
+ assert len (cs .collections ) == 1
1383
+ paths = cs .collections [0 ].get_paths ()
1384
+ assert len (paths ) == 1
1385
+ expected_vertices = [[3 , 1 ], [3 , 3 ], [1 , 3 ], [1 , 1 ], [3 , 1 ]]
1386
+ assert_array_almost_equal (paths [0 ].vertices , expected_vertices )
1387
+ assert_array_equal (paths [0 ].codes , [1 , 2 , 2 , 2 , 79 ])
1388
+ assert_array_almost_equal (paths [0 ].to_polygons (), [expected_vertices ])
1389
+
1390
+ # Polygon following boundary and inside domain
1391
+ cs = ax .tricontourf (triang , [1 , 0 , 0 , 0 , 0 ], levels = [0.5 , 1.5 ])
1392
+ assert len (cs .collections ) == 1
1393
+ paths = cs .collections [0 ].get_paths ()
1394
+ assert len (paths ) == 1
1395
+ expected_vertices = [[2 , 0 ], [1 , 1 ], [0 , 2 ], [0 , 0 ], [2 , 0 ]]
1396
+ assert_array_almost_equal (paths [0 ].vertices , expected_vertices )
1397
+ assert_array_equal (paths [0 ].codes , [1 , 2 , 2 , 2 , 79 ])
1398
+ assert_array_almost_equal (paths [0 ].to_polygons (), [expected_vertices ])
1399
+
1400
+ # Polygon is outer boundary with hole
1401
+ cs = ax .tricontourf (triang , [0 , 0 , 0 , 0 , 1 ], levels = [- 0.5 , 0.5 ])
1402
+ assert len (cs .collections ) == 1
1403
+ paths = cs .collections [0 ].get_paths ()
1404
+ assert len (paths ) == 1
1405
+ expected_vertices = [[0 , 0 ], [4 , 0 ], [4 , 4 ], [0 , 4 ], [0 , 0 ],
1406
+ [1 , 1 ], [1 , 3 ], [3 , 3 ], [3 , 1 ], [1 , 1 ]]
1407
+ assert_array_almost_equal (paths [0 ].vertices , expected_vertices )
1408
+ assert_array_equal (paths [0 ].codes , [1 , 2 , 2 , 2 , 79 , 1 , 2 , 2 , 2 , 79 ])
1409
+ assert_array_almost_equal (paths [0 ].to_polygons (), np .split (expected_vertices , [5 ]))
0 commit comments