Ask Your Question
1

Is there a way to save to to animations in the same avi file

asked 2011-12-08 06:17:02 -0500

Shashank gravatar image

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.

edit retag flag offensive close merge delete

3 answers

Sort by ยป oldest newest most voted
1

answered 2011-12-10 01:35:40 -0500

Jason Grout gravatar image

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: http://matplotlib.sourceforge.net/exa...

edit flag offensive delete link more

Comments

I 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?

Shashank gravatar imageShashank ( 2011-12-10 05:17:47 -0500 )edit

Just 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"

Shashank gravatar imageShashank ( 2011-12-10 06:17:21 -0500 )edit

I 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.

Shashank gravatar imageShashank ( 2011-12-10 06:50:20 -0500 )edit

I accepted the answer because I am pretty sure it will soon work in sage even though it does not work in sage right now.

Shashank gravatar imageShashank ( 2011-12-12 05:37:39 -0500 )edit
0

answered 2011-12-09 06:45:13 -0500

parzan gravatar image

updated 2011-12-09 06:45:21 -0500

edit flag offensive delete link more

Comments

I 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.

Shashank gravatar imageShashank ( 2011-12-09 08:37:41 -0500 )edit
0

answered 2011-12-09 10:20:55 -0500

parzan gravatar image

updated 2011-12-10 00:31:00 -0500

This is based on http://www.imagemagick.org/Usage/anim... . Naturally, you need imagemagick 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 and here. 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.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

Stats

Asked: 2011-12-08 06:17:02 -0500

Seen: 910 times

Last updated: Dec 10 '11