Skip to content

Disable discarded animation warning on save #25339

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

Merged
merged 1 commit into from
Mar 2, 2023
Merged
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
14 changes: 9 additions & 5 deletions lib/matplotlib/animation.py
Original file line number Diff line number Diff line change
Expand Up @@ -992,6 +992,15 @@ def func(current_frame: int, total_frames: int) -> Any
is a `.MovieWriter`, a `RuntimeError` will be raised.
"""

all_anim = [self]
if extra_anim is not None:
all_anim.extend(anim for anim in extra_anim
if anim._fig is self._fig)

# Disable "Animation was deleted without rendering" warning.
for anim in all_anim:
anim._draw_was_started = True

if writer is None:
writer = mpl.rcParams['animation.writer']
elif (not isinstance(writer, str) and
Expand Down Expand Up @@ -1030,11 +1039,6 @@ def func(current_frame: int, total_frames: int) -> Any
if metadata is not None:
writer_kwargs['metadata'] = metadata

all_anim = [self]
if extra_anim is not None:
all_anim.extend(anim for anim in extra_anim
if anim._fig is self._fig)

# If we have the name of a writer, instantiate an instance of the
# registered class.
if isinstance(writer, str):
Expand Down
4 changes: 2 additions & 2 deletions lib/matplotlib/tests/test_animation.py
Original file line number Diff line number Diff line change
Expand Up @@ -514,5 +514,5 @@ def test_movie_writer_invalid_path(anim):
else:
match_str = re.escape("[Errno 2] No such file or directory: '/foo")
with pytest.raises(FileNotFoundError, match=match_str):
_ = anim.save("/foo/bar/aardvark/thiscannotreallyexist.mp4",
writer=animation.FFMpegFileWriter())
anim.save("/foo/bar/aardvark/thiscannotreallyexist.mp4",
writer=animation.FFMpegFileWriter())