ASKSAGE: Sage Q&A Forum - RSS feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Mon, 12 Dec 2011 12:37:39 +0100Is there a way to save to to animations in the same avi filehttps://ask.sagemath.org/question/8538/is-there-a-way-to-save-to-to-animations-in-the-same-avi-file/I have two animations, I created using the animate command, which I want to save in the same avi or gif file one below another. Is there a way to do it. I tried (a+b).savefig(), but it saves the two animations on top of one another. I want something like the graphics_array but for animations.
Thanks in advance.Thu, 08 Dec 2011 13:17:02 +0100https://ask.sagemath.org/question/8538/is-there-a-way-to-save-to-to-animations-in-the-same-avi-file/Answer by parzan for <p>I have two animations, I created using the animate command, which I want to save in the same avi or gif file one below another. Is there a way to do it. I tried (a+b).savefig(), but it saves the two animations on top of one another. I want something like the graphics_array but for animations. </p>
<p>Thanks in advance.</p>
https://ask.sagemath.org/question/8538/is-there-a-way-to-save-to-to-animations-in-the-same-avi-file/?answer=12985#post-id-12985Does this help?
[http://www.sagemath.org/doc/reference/sage/plot/animate.html?highlight=graphics_array#sage.plot.animate.Animation.graphics_array](http://www.sagemath.org/doc/reference/sage/plot/animate.html?highlight=graphics_array#sage.plot.animate.Animation.graphics_array)
Fri, 09 Dec 2011 13:45:13 +0100https://ask.sagemath.org/question/8538/is-there-a-way-to-save-to-to-animations-in-the-same-avi-file/?answer=12985#post-id-12985Comment by Shashank for <p>Does this help?</p>
<p><a href="http://www.sagemath.org/doc/reference/sage/plot/animate.html?highlight=graphics_array#sage.plot.animate.Animation.graphics_array">http://www.sagemath.org/doc/reference/sage/plot/animate.html?highlight=graphics_array#sage.plot.animate.Animation.graphics_array</a></p>
https://ask.sagemath.org/question/8538/is-there-a-way-to-save-to-to-animations-in-the-same-avi-file/?comment=20730#post-id-20730I tried it. Does not work. It works for plots not for animations. If I animate graphics array, I get animations on top of each other. I don't want that. I am trying to do a presentation where I have a plot changing as a function of time. And I have two such plots for different inputs. I want to show them side by side for comparison, but they should be synced. I have two animations in two gif files. But when I open them in my presentation they are not synced.Fri, 09 Dec 2011 15:37:41 +0100https://ask.sagemath.org/question/8538/is-there-a-way-to-save-to-to-animations-in-the-same-avi-file/?comment=20730#post-id-20730Answer by parzan for <p>I have two animations, I created using the animate command, which I want to save in the same avi or gif file one below another. Is there a way to do it. I tried (a+b).savefig(), but it saves the two animations on top of one another. I want something like the graphics_array but for animations. </p>
<p>Thanks in advance.</p>
https://ask.sagemath.org/question/8538/is-there-a-way-to-save-to-to-animations-in-the-same-avi-file/?answer=12987#post-id-12987This is based on http://www.imagemagick.org/Usage/anim_mods/#append . Naturally, you need [imagemagick](http://www.imagemagick.org) installed.
Say you created `pic1.gif` and `pic2.gif`, with the same number of frames:
sage: animate([sin(x + float(k)) for k in srange(0,2*pi,0.3)],xmin=0, xmax=2*pi, figsize=[2,1]).save('pic1.gif')
sage: animate([cos(x + float(k)) for k in srange(0,2*pi,0.3)],xmin=0, xmax=2*pi, figsize=[2,1]).save('pic2.gif')
Download and make executable the scripts [here](http://www.imagemagick.org/Usage/scripts/anim2gif) and [here](http://www.imagemagick.org/Usage/scripts/gif2anim).
Execute the following, changing NUM_FRAMES to the number of frames (21 here, look at the files generated by `gif2anim` if you are not sure):
gif2anim -c pic1.gif
gif2anim -c pic2.gif
for i in `seq -f '%03g' 1 NUM_FRAMES`; do convert pic1_$i.gif pic2_$i.gif -append pic3_$i.gif; done
anim2gif -c -g -b pic3 pic1.anim
You should have `pic3.gif` with the two animation vertically stacked. If you change `-append` to `+append` you get them side by side.
Fri, 09 Dec 2011 17:20:55 +0100https://ask.sagemath.org/question/8538/is-there-a-way-to-save-to-to-animations-in-the-same-avi-file/?answer=12987#post-id-12987Answer by Jason Grout for <p>I have two animations, I created using the animate command, which I want to save in the same avi or gif file one below another. Is there a way to do it. I tried (a+b).savefig(), but it saves the two animations on top of one another. I want something like the graphics_array but for animations. </p>
<p>Thanks in advance.</p>
https://ask.sagemath.org/question/8538/is-there-a-way-to-save-to-to-animations-in-the-same-avi-file/?answer=12988#post-id-12988If you wanted to install the newest version of matplotlib (which is what Sage uses to draw 2d graphics), you could use the new matplotlib animation framework. Here's an example like what you are asking about: http://matplotlib.sourceforge.net/examples/animation/subplots.htmlSat, 10 Dec 2011 08:35:40 +0100https://ask.sagemath.org/question/8538/is-there-a-way-to-save-to-to-animations-in-the-same-avi-file/?answer=12988#post-id-12988Comment by Shashank for <p>If you wanted to install the newest version of matplotlib (which is what Sage uses to draw 2d graphics), you could use the new matplotlib animation framework. Here's an example like what you are asking about: <a href="http://matplotlib.sourceforge.net/examples/animation/subplots.html">http://matplotlib.sourceforge.net/exa...</a></p>
https://ask.sagemath.org/question/8538/is-there-a-way-to-save-to-to-animations-in-the-same-avi-file/?comment=20728#post-id-20728I just tried running the example and I get an error, "ImportError: No module named animation". I am using version 4.7.2. It there something I have to install additionally to make it work? Sat, 10 Dec 2011 12:17:47 +0100https://ask.sagemath.org/question/8538/is-there-a-way-to-save-to-to-animations-in-the-same-avi-file/?comment=20728#post-id-20728Comment by Shashank for <p>If you wanted to install the newest version of matplotlib (which is what Sage uses to draw 2d graphics), you could use the new matplotlib animation framework. Here's an example like what you are asking about: <a href="http://matplotlib.sourceforge.net/examples/animation/subplots.html">http://matplotlib.sourceforge.net/exa...</a></p>
https://ask.sagemath.org/question/8538/is-there-a-way-to-save-to-to-animations-in-the-same-avi-file/?comment=20726#post-id-20726I manages to install matplotlib 1.1 on my system python, and make it spit out a bunch of png files. I then used mencoder to convert it to a avi. So my problem is solved for now, though it is not as smooth as I would have wanted it to be. It would be great if the matplotlib in sage could be upgraded to 1.1 soon. Sat, 10 Dec 2011 13:50:20 +0100https://ask.sagemath.org/question/8538/is-there-a-way-to-save-to-to-animations-in-the-same-avi-file/?comment=20726#post-id-20726Comment by Shashank for <p>If you wanted to install the newest version of matplotlib (which is what Sage uses to draw 2d graphics), you could use the new matplotlib animation framework. Here's an example like what you are asking about: <a href="http://matplotlib.sourceforge.net/examples/animation/subplots.html">http://matplotlib.sourceforge.net/exa...</a></p>
https://ask.sagemath.org/question/8538/is-there-a-way-to-save-to-to-animations-in-the-same-avi-file/?comment=20727#post-id-20727Just realised that the latest sage version (4.7.2) has matplotlib 1.0.1. I don't know how to upgrade it. So I just upgraded just install the latest matplotlib using easy_install and copied the matplotlib directory to $(sage)/local/lib/python2.6/site-packages. Now when I try to save the plots as a mp4 movie I just get a bunch of images and an error "Traceback (most recent call last): cnt = 0
File "", line 1, in <module>
File "/private/var/folders/p8/p8t8MhXCF0uDsptKlAw5Yk+++TI/-Tmp-/tmpxz1OZL/___code___.py", line 39, in <module>
exec compile(u"ani.save('test.mp4')" + '\n', '', 'single')
File "", line 1, in <module>
File "/Applications/sage/local/lib/python2.6/site-packages/matplotlib/animation.py", line 127, in save
self._make_movie(filename, fps, codec, fr"Sat, 10 Dec 2011 13:17:21 +0100https://ask.sagemath.org/question/8538/is-there-a-way-to-save-to-to-animations-in-the-same-avi-file/?comment=20727#post-id-20727Comment by Shashank for <p>If you wanted to install the newest version of matplotlib (which is what Sage uses to draw 2d graphics), you could use the new matplotlib animation framework. Here's an example like what you are asking about: <a href="http://matplotlib.sourceforge.net/examples/animation/subplots.html">http://matplotlib.sourceforge.net/exa...</a></p>
https://ask.sagemath.org/question/8538/is-there-a-way-to-save-to-to-animations-in-the-same-avi-file/?comment=20718#post-id-20718I accepted the answer because I am pretty sure it will soon work in sage even though it does not work in sage right now.Mon, 12 Dec 2011 12:37:39 +0100https://ask.sagemath.org/question/8538/is-there-a-way-to-save-to-to-animations-in-the-same-avi-file/?comment=20718#post-id-20718