Ask Your Question
0

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

asked 2024-01-16 17:01:00 +0100

mlv gravatar image

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

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

answered 2024-01-16 18:06:28 +0100

Emmanuel Charpentier gravatar image

This works :

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

The point is to force min and max ordinates, forting all the frames to have the saem height.

HTH,

edit flag offensive delete link more

Comments

Thanks for the prompt reply! It works!

mlv gravatar imagemlv ( 2024-01-16 18:24:08 +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: 2024-01-16 17:01:00 +0100

Seen: 156 times

Last updated: Jan 16