From c998fd852ac8fef041cc0476c4c03833feff317e Mon Sep 17 00:00:00 2001 From: alphanoobie Date: Wed, 14 May 2025 15:31:11 +0930 Subject: [PATCH 1/2] remove if image from composting --- lib/matplotlib/axes/_base.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/matplotlib/axes/_base.py b/lib/matplotlib/axes/_base.py index 15f8e97b449f..508f42c51ef2 100644 --- a/lib/matplotlib/axes/_base.py +++ b/lib/matplotlib/axes/_base.py @@ -3174,7 +3174,7 @@ def draw(self, renderer): if not self.get_figure(root=True).canvas.is_saving(): artists = [ a for a in artists - if not a.get_animated() or isinstance(a, mimage.AxesImage)] + if not a.get_animated()] artists = sorted(artists, key=attrgetter('zorder')) # rasterize artists with negative zorder From 6882aa5d061e1865e572cf7cfb280b646dc051ee Mon Sep 17 00:00:00 2001 From: alphanoobie Date: Wed, 14 May 2025 15:41:39 +0930 Subject: [PATCH 2/2] test if draw is called --- lib/matplotlib/tests/test_axes.py | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/lib/matplotlib/tests/test_axes.py b/lib/matplotlib/tests/test_axes.py index 5d11964cb613..71145429ccd9 100644 --- a/lib/matplotlib/tests/test_axes.py +++ b/lib/matplotlib/tests/test_axes.py @@ -37,13 +37,14 @@ import matplotlib.text as mtext import matplotlib.ticker as mticker import matplotlib.transforms as mtransforms +from matplotlib.backends.backend_agg import FigureCanvasAgg import mpl_toolkits.axisartist as AA # type: ignore[import] from numpy.testing import ( assert_allclose, assert_array_equal, assert_array_almost_equal) from matplotlib.testing.decorators import ( image_comparison, check_figures_equal, remove_ticks_and_titles) from matplotlib.testing._markers import needs_usetex - +from unittest.mock import MagicMock # Note: Some test cases are run twice: once normally and once with labeled data # These two must be defined in the same test function or need to have # different baseline images to prevent race conditions when pytest runs @@ -9753,3 +9754,22 @@ def test_pie_all_zeros(): fig, ax = plt.subplots() with pytest.raises(ValueError, match="All wedge sizes are zero"): ax.pie([0, 0], labels=["A", "B"]) + + +def test_animated_artists_not_drawn_by_default(): + fig, (ax1, ax2) = plt.subplots(ncols=2) + canvas = FigureCanvasAgg(fig) + + imdata = np.random.random((20, 20)) + lndata = imdata[0] + + im = ax1.imshow(imdata, animated=True) + (ln,) = ax2.plot(lndata, animated=True) + + im.draw = MagicMock(name="im.draw") + ln.draw = MagicMock(name="ln.draw") + + canvas.draw() + + im.draw.assert_not_called() + ln.draw.assert_not_called()