Ask Your Question
1

How to save plots to list?

asked 2015-12-19 12:45:10 +0200

alexander-wilms gravatar image

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 flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted
0

answered 2015-12-19 12:57:37 +0200

alexander-wilms gravatar image
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');
edit flag offensive delete link more
0

answered 2015-12-27 08:49:31 +0200

Eugene gravatar image

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)
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

1 follower

Stats

Asked: 2015-12-19 12:43:15 +0200

Seen: 341 times

Last updated: Dec 27 '15