From 083b381f1306f9cd6f89f021218d151fbcfabda8 Mon Sep 17 00:00:00 2001 From: Tim Hoffmann <2836374+timhoffm@users.noreply.github.com> Date: Thu, 9 Sep 2021 22:44:30 +0200 Subject: [PATCH] Backport PR #21017: FIX: Don't subslice lines if non-standard transform --- lib/matplotlib/lines.py | 3 ++- lib/matplotlib/tests/test_lines.py | 12 ++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/lib/matplotlib/lines.py b/lib/matplotlib/lines.py index 1203862a3f50..658900da9e91 100644 --- a/lib/matplotlib/lines.py +++ b/lib/matplotlib/lines.py @@ -677,7 +677,8 @@ def recache(self, always=False): self.axes.name == 'rectilinear' and self.axes.get_xscale() == 'linear' and self._markevery is None and - self.get_clip_on()): + self.get_clip_on() and + self.get_transform() == self.axes.transData): self._subslice = True nanmask = np.isnan(x) if nanmask.any(): diff --git a/lib/matplotlib/tests/test_lines.py b/lib/matplotlib/tests/test_lines.py index def26456bb36..a9e52ed26850 100644 --- a/lib/matplotlib/tests/test_lines.py +++ b/lib/matplotlib/tests/test_lines.py @@ -16,6 +16,7 @@ from matplotlib.markers import MarkerStyle from matplotlib.path import Path import matplotlib.pyplot as plt +import matplotlib.transforms as mtransforms from matplotlib.testing.decorators import image_comparison, check_figures_equal @@ -131,6 +132,17 @@ def test_drawstyle_variants(): ax.set(xlim=(0, 2), ylim=(0, 2)) +@check_figures_equal(extensions=('png',)) +def test_no_subslice_with_transform(fig_ref, fig_test): + ax = fig_ref.add_subplot() + x = np.arange(2000) + ax.plot(x + 2000, x) + + ax = fig_test.add_subplot() + t = mtransforms.Affine2D().translate(2000.0, 0.0) + ax.plot(x, x, transform=t+ax.transData) + + def test_valid_drawstyles(): line = mlines.Line2D([], []) with pytest.raises(ValueError):