Skip to content

Commit 5c35af1

Browse files
committed
allsegs and allkinds return individual segments
1 parent 7d2acfd commit 5c35af1

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

lib/matplotlib/contour.py

Lines changed: 4 additions & 2 deletions
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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -819,6 +819,20 @@ 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"):

0 commit comments

Comments
 (0)