Problem with animation.save and extra_anim

I'm stuck on animation.save. I cannot seem to save two animations into a
single output file using the keyword extra_anim. It only saves the second of
the two animations, even though each animation can be saved correctly to its
own file.

I've tried several different combinations of FuncAnimation and
ArtistAnimation for the two animations, but all failed. Below is a very
minimal example that illustrates the error. I'm using a Linux computer with
version 1.5.1 of matplotlib installed. ffmpeg is the default
animation.writer and mpeg4 is the default animation.codec.

I should also say that I'm fairly new to python (1+ years), but very new to
its animation. I have, however, spent considerable time researching this
problem on the internet. And I've also read the chapter on animations in Ben
Root's book.

Any help would be much appreciated.

···

-------------------
import numpy as np
import matplotlib.pyplot as plt
from matplotlib import animation

# initialize
xdata = np.array([0.2, 0.4, 0.6, 0.8])
ydata = np.array([0, 0, 0, 0])
anims = [] # list of animations

# set up figure
fig = plt.figure(figsize=(8,1.25))
ax = fig.add_subplot(111)
ax.set_xlim(0, 1)
ax.set_ylim(-0.5, 0.5)

# first animation, with FuncAnimation
line, = ax.plot([], [])
line, = ax.plot(xdata, ydata, 'ro')

def init():
    line.set_data(xdata, ydata)
    return line,

def animate(i): # update function
    ax.figure.canvas.draw()
    return line,

anim0 = animation.FuncAnimation(fig, animate, init_func=init, frames=100,
interval=20, blit=False)
anim0.save('anim0.mp4', extra_args=['-vcodec', 'libx264'])

# second animation, with ArtistAnimation
ax.set_xlim(0.5, 1)

frame_list = []
for i in range(100):
    frame = ax.plot(xdata, ydata, 'ro')
    frame_list.append(frame)
anim1 = animation.ArtistAnimation(fig, frame_list, interval=20,
repeat=False)
anim1.save('anim1.mp4', extra_args=['-vcodec', 'libx264'])

# combine the two animations
anims = [anim0, anim1]
anims[0].save('anims.mp4', extra_args=['-vcodec', 'libx264'],
extra_anim=anims[1:])

--
View this message in context: http://matplotlib.1069221.n5.nabble.com/Problem-with-animation-save-and-extra-anim-tp46844.html
Sent from the matplotlib - users mailing list archive at Nabble.com.

Update 09-Mar-2016
1. I commented out the two individual saves (for anim0 and anim1). Same
result; only the second animation appears in the mp4 file when using the
extra_anim keyword.
2. I also ran this new script in a python shell instead of a jupyter
notebook. Same result.
3. I read issues #5399 and #5822 on github re similar save problems with
matplotlib animation. Those seem not be be related to the issue I raise
here.

Would very much appreciate your help.

···

--
View this message in context: http://matplotlib.1069221.n5.nabble.com/Problem-with-animation-save-and-extra-anim-tp46844p46846.html
Sent from the matplotlib - users mailing list archive at Nabble.com.

I made a detour around this problem, so it's no longer a pressing concern.
But I'd still like to understand the issue better. Did it occur because of
user (ie, my) inexperience and error? Or is it a bug in animation.save? Or
something else? Thanks.

···

--
View this message in context: http://matplotlib.1069221.n5.nabble.com/Problem-with-animation-save-and-extra-anim-tp46844p46886.html
Sent from the matplotlib - users mailing list archive at Nabble.com.

It seems like you have a few things mixed up here in your example. First,
the "animate()" function shouldn't be doing any draw() calls. The animation
infrastructure is responsible for that. The purpose of the "update"
function for FuncAnimation is to update any of the artists and return what
was updated.

Also, with this example, I don't see how it is possible to distinguish
between the ArtistAnimation part and the FuncAnimation part. They are both
drawing the same animation, right?

Ben Root

···

On Mon, Mar 14, 2016 at 7:32 AM, gml <gml at garymlewis.com> wrote:

I made a detour around this problem, so it's no longer a pressing concern.
But I'd still like to understand the issue better. Did it occur because of
user (ie, my) inexperience and error? Or is it a bug in animation.save? Or
something else? Thanks.

--
View this message in context:
http://matplotlib.1069221.n5.nabble.com/Problem-with-animation-save-and-extra-anim-tp46844p46886.html
Sent from the matplotlib - users mailing list archive at Nabble.com.
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users at python.org
Matplotlib-users Info Page

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/matplotlib-users/attachments/20160314/96ac8cc0/attachment.html&gt;

As you say, it's true that in my example both ArtistAnimation and
FuncAnimation were static multi-frame "animations" of a 1D plot of points.
But when done with a thousand or so Cantor set points, the static plot and
the animated plot where xlim narrows around a clump of points are really
quite effective. It's just that I cannot use animation.save and extra_anim
to save the two animations into a single file. And it's not clear to me
whether the problem is the python code I wrote or whether there's a bug in
animation.save.

···

--
View this message in context: http://matplotlib.1069221.n5.nabble.com/Problem-with-animation-save-and-extra-anim-tp46844p46897.html
Sent from the matplotlib - users mailing list archive at Nabble.com.