Skip to content

Commit b40f27c

Browse files
authored
Merge pull request #27041 from meeseeksmachine/auto-backport-of-pr-26908-on-v3.8.x
Backport PR #26908 on branch v3.8.x (`allsegs` and `allkinds` return individual segments)
2 parents 144765a + 6f66c7e commit b40f27c

File tree

2 files changed

+18
-6
lines changed

2 files changed

+18
-6
lines changed

lib/matplotlib/contour.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -935,9 +935,11 @@ def __init__(self, ax, *args,
935935
)
936936

937937
allsegs = _api.deprecated("3.8", pending=True)(property(lambda self: [
938-
p.vertices for c in self.collections for p in c.get_paths()]))
938+
[subp.vertices for subp in p._iter_connected_components()]
939+
for p in self.get_paths()]))
939940
allkinds = _api.deprecated("3.8", pending=True)(property(lambda self: [
940-
p.codes for c in self.collections for p in c.get_paths()]))
941+
[subp.codes for subp in p._iter_connected_components()]
942+
for p in self.get_paths()]))
941943
tcolors = _api.deprecated("3.8")(property(lambda self: [
942944
(tuple(rgba),) for rgba in self.to_rgba(self.cvalues, self.alpha)]))
943945
tlinewidths = _api.deprecated("3.8")(property(lambda self: [

lib/matplotlib/tests/test_contour.py

+14-4
Original file line numberDiff line numberDiff line change
@@ -819,14 +819,24 @@ def test_all_nan():
819819
2.4e-14, 5e-14, 7.5e-14, 1e-13])
820820

821821

822+
def test_allsegs_allkinds():
823+
x, y = np.meshgrid(np.arange(0, 10, 2), np.arange(0, 10, 2))
824+
z = np.sin(x) * np.cos(y)
825+
826+
cs = plt.contour(x, y, z, levels=[0, 0.5])
827+
828+
# Expect two levels, first with 5 segments and the second with 4.
829+
with pytest.warns(PendingDeprecationWarning, match="all"):
830+
for result in [cs.allsegs, cs.allkinds]:
831+
assert len(result) == 2
832+
assert len(result[0]) == 5
833+
assert len(result[1]) == 4
834+
835+
822836
def test_deprecated_apis():
823837
cs = plt.contour(np.arange(16).reshape((4, 4)))
824838
with pytest.warns(mpl.MatplotlibDeprecationWarning, match="collections"):
825839
colls = cs.collections
826-
with pytest.warns(PendingDeprecationWarning, match="allsegs"):
827-
assert cs.allsegs == [p.vertices for c in colls for p in c.get_paths()]
828-
with pytest.warns(PendingDeprecationWarning, match="allkinds"):
829-
assert cs.allkinds == [p.codes for c in colls for p in c.get_paths()]
830840
with pytest.warns(mpl.MatplotlibDeprecationWarning, match="tcolors"):
831841
assert_array_equal(cs.tcolors, [c.get_edgecolor() for c in colls])
832842
with pytest.warns(mpl.MatplotlibDeprecationWarning, match="tlinewidths"):

0 commit comments

Comments
 (0)