# How to save plots to list?

I'd like to create an animation of a 2D plot. This works:

anz=10;
Lambda=2*7/anz*pi;
xm=R*Lambda;
plots = [parametric_plot((x(phi,1),y(phi,1)),(phi,0,2*pi))+circle((x(2*i/anz*pi,1),y(2*i/anz*pi,1)),R/40,color='red')+circle((R*2*i/anz*pi,R),R,color='cyan')+circle((R*2*i/anz*pi,R),R/25,color='magenta')+arc((R*2*i/anz*pi,R), R, sector=(-2*i/anz*pi-pi/2,-pi/2),color='red') for i in range(0,anz)]

anim=animate(plots);
anim;

But I'd like to make it a bit more readable, like this:

anz=10;

for i in range(0,anz):
Lambda=2*i/anz*pi;
xm=R*Lambda;
p[i]=parametric_plot((x(phi,1),y(phi,1)),(phi,0,2*pi));
p[i]+=circle((x(Lambda,1),y(Lambda,1)),R/40,color='red');
p[i]+=circle((xm,R),R,color='cyan');
p[i]+=circle((xm,R),R/25,color='magenta');
p[i]+=arc((xm,R), R, sector=(-Lambda-pi/2,-pi/2),color='red');

p_anim=animate(p)
p;

How do I create a list of GraphicPrimitives and so that this works?

edit retag close merge delete

Sort by ยป oldest newest most voted
anz=10;

empty = Graphics()
p = graphics_array([empty, empty, empty, empty, empty, empty, empty, empty, empty, empty])

for i in range(0,anz):
Lambda=2*i/anz*pi;
xm=R*Lambda;
p[i]=parametric_plot((x(phi,1),y(phi,1)),(phi,0,2*pi));
p[i]+=circle((x(Lambda,1),y(Lambda,1)),R/40,color='red');
p[i]+=circle((xm,R),R,color='cyan');
p[i]+=circle((xm,R),R/25,color='magenta');
p[i]+=arc((xm,R), R, sector=(-Lambda-pi/2,-pi/2),color='red');
#p[i]+=plot([(xm,R),(x(Lambda,1),y(Lambda,1))],color='black');
#p[i]+=plot([(0,-0.02),(xm,-0.02)],color='brown');
more

The example you've provided is not working for me 'as is', an exception occurs:

TypeError: descriptor 'parent' of 'sage.structure.sage_object.SageObject' object needs an argument

Nonetheless if you need to create an animation from a complicated plot, why not just use Python's list? animate function seems to work fin with that. Here is an example of animation from the frames created from two plots each:

import numpy as np

plots = []

N = 64

for phi in np.arange(0, pi, pi / N):
frame = plot(sin(x + phi), 0, 2 * pi)
frame += line([(0, sin(phi)), (2 * pi, sin(phi))], linestyle='--')
plots.append(frame)

animate(plots)
more