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