Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Can we control the size of a plot, so I can use apng() in animation

I know how to control the size of a plot when I show the plot, eg: g.show(figsize=[3,5])

The following Sagemath code works without installing ImageMagick or FFmpeg, it is quite convenient.

frames = [plot(cos(k*x), (-pi, pi)) for k in range(1,7)]
a = animate(frames)
a.apng(savefile='ex1.png', show_path=True)

Unfortunately, the following will produce error:

frames = [plot(cos(x^k), (-2, 2)) for k in range(1,7)]
a = animate(frames)
a.apng(savefile='ex2.png', show_path=True)

After I done some debugging, I found that the individual frames produced in the for loop all have the same size. The he individual frames produced in the for loop do not all have the same size. I played with the apng() more and find that apng() seems to expect all frames to have the same size.

How can we control the plot so that the image produced in the memory all have the same size. I am not concerning with the 'display size on the screen', I am concerning with the 'size as seen by the apng() in the memory' in the for loop.

I would like to have the following option to force all frames resize to the same size when putting all frames together.

animate(frames, figsize=[3,5]). or apng(frames, figsize=[3,5])