matplotlib
matplotlib copied to clipboard
directory-of-files MovieWriter subclass
Derived from https://stackoverflow.com/questions/41230286/matplotlib-animation-write-to-png-files-without-third-party-module
Some version of my answer http://stackoverflow.com/a/41273312/380231
import matplotlib.animation as ma
class BunchOFiles(ma.FileMovieWriter):
def setup(self, fig, dpi, frame_prefix):
super().setup(fig, dpi, frame_prefix, clear_temp=False)
def _run(self):
# Uses subprocess to call the program for assembling frames into a
# movie file. *args* returns the sequence of command line arguments
# from a few configuration options.
pass
def grab_frame(self, **savefig_kwargs):
'''
Grab the image information from the figure and save as a movie frame.
All keyword arguments in savefig_kwargs are passed on to the 'savefig'
command that saves the figure.
'''
# Tell the figure to save its data to the sink, using the
# frame format and dpi.
with self._frame_sink() as myframesink:
self.fig.savefig(myframesink, format=self.frame_format,
dpi=self.dpi, **savefig_kwargs)
def cleanup(self):
# explictily skip a step in the mro
ma.MovieWriter.cleanup(self)
should end up in the animation module in the case where people just want a folder of png and don't have any of the other external tools installed.
Good idea. Along with it, we should have standalone wrappers for those external tools, acting on the folder of pngs. This makes it efficient to test different parameters for the generated animation, or to make several versions of it.
Could possibly make it possible to adapt the image comparison test framework to work off a directory of pngs, so we could have some animation tests?
On Dec 23, 2016 4:56 PM, "Eric Firing" [email protected] wrote:
Good idea. Along with it, we should have standalone wrappers for those external tools, acting on the folder of pngs. This makes it efficient to test different parameters for the generated animation, or to make several versions of it.
— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/matplotlib/matplotlib/issues/7679#issuecomment-269049837, or mute the thread https://github.com/notifications/unsubscribe-auth/AARy-Lafe82gkA9fF4NJZ3OF7edYbOEvks5rLEN7gaJpZM4LU9UO .
Couldn't that just be done by adapting FileMovieWriter accordingly? In one of my oldest PRs (#3536) I argued that FileMovieWriter should default to putting its files in a tempdir anyways; it seems reasonable to just make it either a tempdir or a dir passed as argument.
clear_temp=False seems to be removed in 3.5.0-b1 - is there an alternative way to achieve this?
If you pass a frame_prefix to setup instead of clear_temp=False, then those files will not be removed.
This issue has been marked "inactive" because it has been 365 days since the last comment. If this issue is still present in recent Matplotlib releases, or the feature request is still wanted, please leave a comment and this label will be removed. If there are no updates in another 30 days, this issue will be automatically closed, but you are free to re-open or create a new issue if needed. We value issue reports, and this procedure is meant to help us resurface and prioritize issues that have not been addressed yet, not make them disappear. Thanks for your help!