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
API: forbid unsafe savefig kwargs to AbstractMovieWriter.grab_frame #25631
Conversation
dbf625e
to
f4943cc
Compare
Completely out of my wheelhouse here, but the comment in the matplotlibrc seems to suggest that matplotlib/lib/matplotlib/mpl-data/matplotlibrc Lines 685 to 688 in 6686f97
Also if you set |
After going down a far deeper rabbit hole than I expected (that involved trying and failin gto get a mpeg4 decoder installed on fedora) to see what import matplotlib.pyplot as plt
fig, ax = plt.subplots()
for j in range(100):
ax.set_title(f"frame {j}")
fig.set_size_inches(j % 10 + 2, j % 10 + 2)
fig.savefig(f"/tmp/mv/frame-{j:04d}.png")
It seems to work (but I would call the output more artistic than informative). I think it is scaling the subsequent files to match the size of the first frame so the axes move / resize frame to frame. We already do some checking in matplotlib/lib/matplotlib/animation.py Lines 1042 to 1057 in 61ed3f4
We talked about this on the call today and the consensus is that while it may "work" with the file based writers, it is likely not what a user wants, if the user wants to save varying size pngs they can still do so (and will have to call ffmpeg them selves), and because this is a lower-level API than I also think there is a consistency arguement that if we prevent something with some writers (because it silently produces totally broken output) we should prevent the same thing in other writers (where it would silently produces silly output). |
f4943cc
to
92f9fb0
Compare
@rcomer I updated the comment in the rcparams. |
_log.info("Disabling savefig.bbox = 'tight', as it may cause " | ||
"frame size to vary, which is inappropriate for " | ||
"animation.") | ||
|
||
# This particular sequence is what contextlib.contextmanager wants |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Side note, but I don't know what this comment is about.
…frame Several of the keyword arguments (dpi, bbox_inches) to savefig will change the dimensions of the rendered figure or byte output (format). Changing these mid-stream in generating a movie will in a best case result in an animation that jumps around and in a worst case silently generate a completely corrupted movie. The rcparam savefig.bbox can have the same effect. The low level AbstractMovieWriter.grab_frame is now strict and will error if any possibly unsafe conditions are met. closes matplotlib#25608 Co-authored-by: Elliott Sales de Andrade <quantum.analyst@gmail.com>
This makes the validation that the rcparams are not going to mess with frame size more generally available without duplicating it.
Technically ffmpeg will stitch a series of different size static images into a movie, however it does so my scaling each subsequent frame to be the dimensions of the first which results in sub-optimal output.
725411a
to
1d4ab69
Compare
PR Summary
closes #25608
Per #25608 (comment) I do not think there is a way to make these keywords work in the context of a saved animation.
PR Checklist
Documentation and Tests
pytest
passes)Release Notes
.. versionadded::
directive in the docstring and documented indoc/users/next_whats_new/
.. versionchanged::
directive in the docstring and documented indoc/api/next_api_changes/
next_whats_new/README.rst
ornext_api_changes/README.rst