From 0f4ec9ae73906a9b87db6867d13e4dcd600c6aaf Mon Sep 17 00:00:00 2001 From: Thomas A Caswell Date: Fri, 9 Dec 2022 12:19:03 -0500 Subject: [PATCH] FIX: do not replace the Axes._children list object Each Artist keeps a reference to `Axes._children.remove` as `art._remove_method`. If we replace the `_children` instance on the Axes with a different list instance the Artists will not be updated and their remove method will refer to the wrong list. This will cause subsequent failures on the next draw because on remove we reset the `art.axes` and `art.figure` to None. xref https://discourse.matplotlib.org/t/host-subplot-and-artist-remove/23374 --- lib/mpl_toolkits/axes_grid1/parasite_axes.py | 2 +- lib/mpl_toolkits/axes_grid1/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 767d0789c24d..b8781a18c22b 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): super().clear() diff --git a/lib/mpl_toolkits/axes_grid1/tests/test_axes_grid1.py b/lib/mpl_toolkits/axes_grid1/tests/test_axes_grid1.py index 70fc22deb85e..be31aa615fdf 100644 --- a/lib/mpl_toolkits/axes_grid1/tests/test_axes_grid1.py +++ b/lib/mpl_toolkits/axes_grid1/tests/test_axes_grid1.py @@ -684,3 +684,14 @@ def test_imagegrid(): im = ax.imshow([[1, 2]], norm=mpl.colors.LogNorm()) cb = ax.cax.colorbar(im) assert isinstance(cb.locator, mticker.LogLocator) + + +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() pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy