Ask Your Question
1

How to zoom in on saved plot?

asked 2021-06-18 20:05:45 +0100

ddxtanx gravatar image

Hello all!

I'm trying to make some animations for a class I'm teaching, but, while I've been able to have them animate the way I want, when I save the animation the objects are really small compared to the size of the file. For example, this is what one frame of the output looks like: imgur.com/a/BURrSXI; but I'd rather have it look like this: imgur.com/a/l3TVDGK. Is there any way I can control the output of Sage so that the objects take up more of the animation/image? Thank you!

Edit: If it helps, I am making my animations with parametric_plot3d and Sphere's. I have a graphics object G that I am adding all of my spheres and parametric plots to. Then, I'm saving that graphics object via the .save method.

num_frames_graph = 100 
frames_list_graph = [0]*10 
frames_list_graph.extend(list(range(0,num_frames_graph))) 
frames_list_graph.extend([num_frames_graph for i in range(0,15)]) 
frames_list_graph.extend(frames_list_graph[::-1]) 
graph_frames = [graph_projection(RDF(time / num_frames_graph)) for time in frames_list_graph]


os.system("mkdir graphFrames")
for i,frame in enumerate(graph_frames):
        frame.save(filename="graphFrames/graph%04d.png"%i, 
            figsize=[12,8], 
            dpi = 1000, 
            xmin = -2.1, 
            xmax = 2.1,  
            ymin = -2.1, 
            ymax = 2.1, 
            zmin=-2.1, 
            zmax=2.1, 
            transparent=True, 
            aspect_ratio=1
        )
os.system('cd graphFrames; convert -delay %s -loop %s *.png "graph.gif"'%(float(100/60),int(0)))

Is the general method of how I'm constructing my animations

edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted
2

answered 2021-06-19 11:07:16 +0100

slelievre gravatar image

Sage 9.3 allows to save a collection of 3d frames as an interactive 3d animated scene.

The result is 3d, has a play/pause button, one navigate the scene both in time (frame by frame or using a play/pause button, playing it once or in a loop), and in space with ways to zoom in and out, rotate, translate the view.

The space navigation can be done while the animation is paused or while it is playing.

After you have produced the collection of 3d scenes with

num_frames_graph = 100 
frames_list_graph = [0]*10 
frames_list_graph.extend(list(range(num_frames_graph))) 
frames_list_graph.extend([num_frames_graph for i in range(15)]) 
frames_list_graph.extend(frames_list_graph[::-1]) 
graph_frames = [graph_projection(RDF(time / num_frames_graph))
                for time in frames_list_graph]

the animation can be constructed as:

animation = animate(frames).interactive()

and then rendered with

animation

or

animation.show()

or saved as html with

animation.save('graph.html')

Returning to the question as asked: to remove the excess whitespace around each frame of your animation, you would either need to adjust the xmin, xmax, ymin, ymax that are used to save each frame as png, or to trim margins after the fact on the obtained png before turning them into an animated gif.

This illustrate the latter option:

os.system('mkdir graphFrames')
for i, frame in enumerate(graph_frames):
    frame.save(filename='graphFrames/graph%04d.png' % i, 
               figsize=[12, 8], 
               dpi=1000, 
               xmin=-2.1, 
               xmax=2.1,  
               ymin=-2.1, 
               ymax=2.1, 
               zmin=-2.1, 
               zmax=2.1, 
               transparent=True, 
               aspect_ratio=1,
              )
os.system('cd graphFrames; '
          'mogrify -trim graph*.png; '
          f'convert -delay {float(100/60)} -loop {int(0)} graph*.png "graph.gif"')
edit flag offensive delete link more
1

answered 2021-06-21 22:17:20 +0100

ddxtanx gravatar image

I ended up changing my scene to use the Tachyon renderer. I was able to control the resolution of my scene with the arguments to the tachyon scene creator as well as control where the camera was, where it looked at, and what the zoom level was. I was also able to enable antialiasing. All of these options reduced whitespace and increased resolution!

This worked because I did not have any parametric surfaces, so I was able to turn my Spheres, Parametric Curves, and Annulus into Tachyon objects quite easily.

edit flag offensive delete link more

Comments

Is that code shared somewhere? I would be interested in taking a look.

slelievre gravatar imageslelievre ( 2021-06-22 01:01:55 +0100 )edit

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: 2021-06-18 19:50:09 +0100

Seen: 956 times

Last updated: Jun 21 '21