Skip to content

Animation docs should include a simple "save as gif with pillow" example #22374

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
anntzer opened this issue Feb 1, 2022 · 15 comments
Closed
Labels
Documentation Good first issue Open a pull request against these issues if there are no active ones! topic: animation
Milestone

Comments

@anntzer
Copy link
Contributor

anntzer commented Feb 1, 2022

Documentation Link

No response

Problem

pillow is the only animation writer that does not require additional dependencies (we already depend on pillow in any case) but it is not the default writer. I think the main animation formation it can save to is gif.

There should be a simple "save as gif with pillow example" with its own entry in https://matplotlib.org/devdocs/gallery/index#animation (although some of the examples have a few lines on saving as mp4 with ffmpeg, 1. it is not even clear from the index which are these examples, and 2. ffmpeg may or may not be present on the user's machine).

Suggested improvement

No response

Matplotlib Version

3.6.0.dev1512

@timhoffm
Copy link
Member

timhoffm commented Feb 2, 2022

What we really need is an animation tutorial/explanation. This should explain the logic of animations and could then also have a section on saving to file. The individual examples should link to the tutorial for further information.

@story645 story645 added the Good first issue Open a pull request against these issues if there are no active ones! label Jul 14, 2022
@story645
Copy link
Member

Labeling good first issue because this is relatively simple and stand alone. Also agree we need a user level "how to animate" tutorial, but I think this example can be generated independent of that.

@kostyafarber
Copy link
Contributor

This sounds interesting. Any suggestions on what animation we would want to use for this example?

@story645
Copy link
Member

story645 commented Sep 25, 2022

I think something small like moving a scatter dot across the page - it's not documented as its own thing like line is (https://matplotlib.org/devdocs/gallery/animation/simple_anim.html#sphx-glr-gallery-animation-simple-anim-py) but is fairly small so won't distract from the save as gif? (plus it works really well as an infinite gif)

ETA: https://matplotlib.org/devdocs/gallery/animation/rain.html#sphx-glr-gallery-animation-rain-py has how to animate scatter, it's just the complex version

@kostyafarber
Copy link
Contributor

No worries I'll have a look at it and try mock something up.

@kostyafarber
Copy link
Contributor

kostyafarber commented Oct 2, 2022

Hey,

Are we thinking something simple like this? (it moves faster and smoother when run from the terminal)

scatter

Also what would be the best way we want to write the save to gif as?

# To save the animation, use e.g.
#
# ani.save("movie.mp4")
#
# or
#
# writer = animation.FFMpegWriter(
#     fps=15, metadata=dict(artist='Me'), bitrate=1800)
# ani.save("movie.mp4", writer=writer)

Something like the above?

Cheers,
Kostya

@kostyafarber
Copy link
Contributor

@story645

@story645
Copy link
Member

story645 commented Oct 4, 2022

that works for me, except the save has to be explicitly using pillow as the writer and the two examples you have are the built in mp4 and ffmpeg.

https://matplotlib.org/stable/api/_as_gen/matplotlib.animation.PillowWriter.html?highlight=pillow#matplotlib.animation.PillowWriter

@kostyafarber
Copy link
Contributor

No worries I'll have a look into it and post the code block here. Thanks.

@kostyafarber
Copy link
Contributor

@story645

How does this look?

# To save the animation using Pillow as a gif, use e.g.
#
# writer = animation.PillowWriter(fps=15,
#                                 metadata=dict(artist='Me'),
#                                 bitrate=1800)
# ani.save('scatter.gif', writer=writer)

@story645
Copy link
Member

story645 commented Oct 4, 2022

I'm not sure if it needs to be in comments

@kostyafarber
Copy link
Contributor

Sure thing I can uncomment in the code.

@kostyafarber
Copy link
Contributor

@story645 just had a thought if it's not in comments when the docs are built will the code generate an image if it has ani.save('scatter.gif', writer=writer) uncommented?

Might be better to comment out then?

@melissawm
Copy link
Member

Now that the animation tutorial has been merged, do we still need to keep this issue open?

@timhoffm
Copy link
Member

@QuLogic QuLogic added this to the v3.7.0 milestone May 26, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Documentation Good first issue Open a pull request against these issues if there are no active ones! topic: animation
Projects
None yet
Development

No branches or pull requests

6 participants