The following doesn't work (but maybe it could after patching animate
). Make a graphics array for each frame of the animation and then use animate
on the result. Something like this:
frames = []
for i in srange(0,2*pi,0.2):
singraph = point((i,sin(i)), color="green", size=50)
singraph += plot(sin(x),(0,2*pi), xmin=0, xmax=7, ymin=-1, ymax=1, figsize=[2,2])
unitcircle = point((cos(i),sin(i)), color="green", size=50)
unitcircle += circle((0,0),1, color="blue", figsize=[2,2])
frames.append(graphics_array([singraph, unitcircle]))
show(animate(frames))
This doesn't work because animate
expects a list of Graphics
objects and GraphicsArray
is not a Graphics
object in Sage because of the way Graphics objects are expected to behave. For example how would adding to GraphicsArray objects be handled? Each array has multiple plots in it so it's not clear what the behavior should be. If you give animate
non Graphics objects, then Sage tries to call plot
on them which is what really fails in this example.
Here is a solution that works. After reading the source code for animate
I discovered that you can "superimpose" two animations frame by frame by simply adding the corresponding animation objects. This isn't documented in the docstring for animate unfortunately. The following code does what you want:
sin_frames = []
circ_frames = []
circ_x = -1.5 # offset center of the circle
circ_y = 0
for i in srange(0,2*pi,0.2):
singraph = point((i,sin(i)), color="green", size=50)
singraph += plot(sin(x),(0,2*pi), xmin=0, xmax=7, ymin=-1, ymax=1, figsize=[2,2], axes=False)
unitcircle = point((cos(i)+circ_x,sin(i)+circ_y), color="green", size=50)
unitcircle += circle((circ_x,circ_y),1, color="blue", figsize=[2,2], axes=False)
sin_frames.append(singraph)
circ_frames.append(unitcircle)
A1 = animate(sin_frames)
A2 = animate(circ_frames)
show(A1+A2) # superimpose frames