Skip to content

Commit 08236ae

Browse files
alphanoobietimhoffmrcomer
authored
Setting imshow(animated=True) still show does not show an image (matplotlib#30052)
--------- Co-authored-by: Tim Hoffmann <2836374+timhoffm@users.noreply.github.com> Co-authored-by: Ruth Comer <10599679+rcomer@users.noreply.github.com>
1 parent 702c669 commit 08236ae

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed

lib/matplotlib/axes/_base.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3206,7 +3206,7 @@ def draw(self, renderer):
32063206
if not self.get_figure(root=True).canvas.is_saving():
32073207
artists = [
32083208
a for a in artists
3209-
if not a.get_animated() or isinstance(a, mimage.AxesImage)]
3209+
if not a.get_animated()]
32103210
artists = sorted(artists, key=attrgetter('zorder'))
32113211

32123212
# rasterize artists with negative zorder

lib/matplotlib/tests/test_axes.py

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import re
1212
import sys
1313
from types import SimpleNamespace
14+
import unittest.mock
1415

1516
import dateutil.tz
1617

@@ -45,7 +46,6 @@
4546
from matplotlib.testing.decorators import (
4647
image_comparison, check_figures_equal, remove_ticks_and_titles)
4748
from matplotlib.testing._markers import needs_usetex
48-
4949
# Note: Some test cases are run twice: once normally and once with labeled data
5050
# These two must be defined in the same test function or need to have
5151
# different baseline images to prevent race conditions when pytest runs
@@ -10018,3 +10018,20 @@ def test_pie_all_zeros():
1001810018
fig, ax = plt.subplots()
1001910019
with pytest.raises(ValueError, match="All wedge sizes are zero"):
1002010020
ax.pie([0, 0], labels=["A", "B"])
10021+
10022+
10023+
def test_animated_artists_not_drawn_by_default():
10024+
fig, (ax1, ax2) = plt.subplots(ncols=2)
10025+
10026+
imdata = np.random.random((20, 20))
10027+
lndata = imdata[0]
10028+
10029+
im = ax1.imshow(imdata, animated=True)
10030+
(ln,) = ax2.plot(lndata, animated=True)
10031+
10032+
with (unittest.mock.patch.object(im, "draw", name="im.draw") as mocked_im_draw,
10033+
unittest.mock.patch.object(ln, "draw", name="ln.draw") as mocked_ln_draw):
10034+
fig.draw_without_rendering()
10035+
10036+
mocked_im_draw.assert_not_called()
10037+
mocked_ln_draw.assert_not_called()

0 commit comments

Comments
 (0)