From fe900c59ea290b87796b736eb65fd1cbf38cdeed Mon Sep 17 00:00:00 2001 From: Kyle Sunden Date: Fri, 9 Dec 2022 13:43:42 -0600 Subject: [PATCH] Backport PR #24677: FIX: do not replace the Axes._children list object Manual backport due to conflicts, which were just additional tests in main from #23861, so simply removed these. --- lib/mpl_toolkits/axes_grid1/parasite_axes.py | 2 +- lib/mpl_toolkits/tests/test_axes_grid1.py | 11 +++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/lib/mpl_toolkits/axes_grid1/parasite_axes.py b/lib/mpl_toolkits/axes_grid1/parasite_axes.py index b959d1f48a49..2313e9672742 100644 --- a/lib/mpl_toolkits/axes_grid1/parasite_axes.py +++ b/lib/mpl_toolkits/axes_grid1/parasite_axes.py @@ -136,7 +136,7 @@ def draw(self, renderer): self._children.extend(ax.get_children()) super().draw(renderer) - self._children = self._children[:orig_children_len] + del self._children[orig_children_len:] def clear(self): for ax in self.parasites: diff --git a/lib/mpl_toolkits/tests/test_axes_grid1.py b/lib/mpl_toolkits/tests/test_axes_grid1.py index 374b8c721f9c..81b4ff91b65c 100644 --- a/lib/mpl_toolkits/tests/test_axes_grid1.py +++ b/lib/mpl_toolkits/tests/test_axes_grid1.py @@ -568,3 +568,14 @@ def test_rgb_axes(): g = rng.random((5, 5)) b = rng.random((5, 5)) ax.imshow_rgb(r, g, b, interpolation='none') + + +def test_removal(): + import matplotlib.pyplot as plt + import mpl_toolkits.axisartist as AA + fig = plt.figure() + ax = host_subplot(111, axes_class=AA.Axes, figure=fig) + col = ax.fill_between(range(5), 0, range(5)) + fig.canvas.draw() + col.remove() + fig.canvas.draw()