Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Setting imshow(animated=True) still show does not show an image #30052

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/matplotlib/axes/_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
22 changes: 21 additions & 1 deletion lib/matplotlib/tests/test_axes.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()
Loading