From 3adeb0006860d9395fa5cbd89b95ef493ad50def Mon Sep 17 00:00:00 2001 From: Antony Lee Date: Wed, 7 Jul 2021 00:01:57 +0200 Subject: [PATCH] Backport PR #20584: FIX: do not simplify path in LineCollection.get_segments Merge pull request #20584 from tacaswell/fix_linecollection_simplified_segments FIX: do not simplify path in LineCollection.get_segments Conflicts: lib/matplotlib/tests/test_collections.py - only backport the new test --- lib/matplotlib/collections.py | 9 ++++++++- lib/matplotlib/tests/test_collections.py | 9 +++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/lib/matplotlib/collections.py b/lib/matplotlib/collections.py index 0e1d225c5209..0213f3cf1633 100644 --- a/lib/matplotlib/collections.py +++ b/lib/matplotlib/collections.py @@ -1494,7 +1494,14 @@ def get_segments(self): segments = [] for path in self._paths: - vertices = [vertex for vertex, _ in path.iter_segments()] + vertices = [ + vertex + for vertex, _ + # Never simplify here, we want to get the data-space values + # back and there in no way to know the "right" simplification + # threshold so never try. + in path.iter_segments(simplify=False) + ] vertices = np.asarray(vertices) segments.append(vertices) diff --git a/lib/matplotlib/tests/test_collections.py b/lib/matplotlib/tests/test_collections.py index d11bab7a022b..536703233978 100644 --- a/lib/matplotlib/tests/test_collections.py +++ b/lib/matplotlib/tests/test_collections.py @@ -868,3 +868,12 @@ def test_array_wrong_dimensions(): pc = plt.pcolormesh(z) pc.set_array(z) # 2D is OK for Quadmesh pc.update_scalarmappable() + + +def test_get_segments(): + segments = np.tile(np.linspace(0, 1, 256), (2, 1)).T + lc = LineCollection([segments]) + + readback, = lc.get_segments() + # these should comeback un-changed! + assert np.all(segments == readback)