@@ -1340,3 +1340,64 @@ 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
+ paths = cs .get_paths ()
1354
+ assert len (paths ) == 1
1355
+ expected_vertices = [[2 , 0 ], [1 , 1 ], [0 , 2 ]]
1356
+ assert_array_almost_equal (paths [0 ].vertices , expected_vertices )
1357
+ assert_array_equal (paths [0 ].codes , [1 , 2 , 2 ])
1358
+ assert_array_almost_equal (
1359
+ paths [0 ].to_polygons (closed_only = False ), [expected_vertices ])
1360
+
1361
+ # Closed line loop inside domain
1362
+ cs = ax .tricontour (triang , [0 , 0 , 0 , 0 , 1 ], levels = [0.5 ])
1363
+ paths = cs .get_paths ()
1364
+ assert len (paths ) == 1
1365
+ expected_vertices = [[3 , 1 ], [3 , 3 ], [1 , 3 ], [1 , 1 ], [3 , 1 ]]
1366
+ assert_array_almost_equal (paths [0 ].vertices , expected_vertices )
1367
+ assert_array_equal (paths [0 ].codes , [1 , 2 , 2 , 2 , 79 ])
1368
+ assert_array_almost_equal (paths [0 ].to_polygons (), [expected_vertices ])
1369
+
1370
+
1371
+ def test_tricontourf_path ():
1372
+ x = [0 , 4 , 4 , 0 , 2 ]
1373
+ y = [0 , 0 , 4 , 4 , 2 ]
1374
+ triang = mtri .Triangulation (x , y )
1375
+ _ , ax = plt .subplots ()
1376
+
1377
+ # Polygon inside domain
1378
+ cs = ax .tricontourf (triang , [0 , 0 , 0 , 0 , 1 ], levels = [0.5 , 1.5 ])
1379
+ paths = cs .get_paths ()
1380
+ assert len (paths ) == 1
1381
+ expected_vertices = [[3 , 1 ], [3 , 3 ], [1 , 3 ], [1 , 1 ], [3 , 1 ]]
1382
+ assert_array_almost_equal (paths [0 ].vertices , expected_vertices )
1383
+ assert_array_equal (paths [0 ].codes , [1 , 2 , 2 , 2 , 79 ])
1384
+ assert_array_almost_equal (paths [0 ].to_polygons (), [expected_vertices ])
1385
+
1386
+ # Polygon following boundary and inside domain
1387
+ cs = ax .tricontourf (triang , [1 , 0 , 0 , 0 , 0 ], levels = [0.5 , 1.5 ])
1388
+ paths = cs .get_paths ()
1389
+ assert len (paths ) == 1
1390
+ expected_vertices = [[2 , 0 ], [1 , 1 ], [0 , 2 ], [0 , 0 ], [2 , 0 ]]
1391
+ assert_array_almost_equal (paths [0 ].vertices , expected_vertices )
1392
+ assert_array_equal (paths [0 ].codes , [1 , 2 , 2 , 2 , 79 ])
1393
+ assert_array_almost_equal (paths [0 ].to_polygons (), [expected_vertices ])
1394
+
1395
+ # Polygon is outer boundary with hole
1396
+ cs = ax .tricontourf (triang , [0 , 0 , 0 , 0 , 1 ], levels = [- 0.5 , 0.5 ])
1397
+ paths = cs .get_paths ()
1398
+ assert len (paths ) == 1
1399
+ expected_vertices = [[0 , 0 ], [4 , 0 ], [4 , 4 ], [0 , 4 ], [0 , 0 ],
1400
+ [1 , 1 ], [1 , 3 ], [3 , 3 ], [3 , 1 ], [1 , 1 ]]
1401
+ assert_array_almost_equal (paths [0 ].vertices , expected_vertices )
1402
+ assert_array_equal (paths [0 ].codes , [1 , 2 , 2 , 2 , 79 , 1 , 2 , 2 , 2 , 79 ])
1403
+ assert_array_almost_equal (paths [0 ].to_polygons (), np .split (expected_vertices , [5 ]))
0 commit comments