First time here? Check out the FAQ!

Ask Your Question
0

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

asked 1 year ago

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

Preview: (hide)

1 Answer

Sort by » oldest newest most voted
0

answered 1 year ago

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,

Preview: (hide)
link

Comments

Thanks for the prompt reply! It works!

mlv gravatar imagemlv ( 1 year ago )

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: 1 year ago

Seen: 178 times

Last updated: Jan 16 '24