Skip to content

Cleanup animation examples #10125

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

Merged
merged 2 commits into from
Jan 17, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 18 additions & 43 deletions doc/api/animation_api.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
======================
``animation`` module
======================
*********
animation
*********

.. automodule:: matplotlib.animation
:no-members:
Expand All @@ -11,7 +11,6 @@
:local:
:backlinks: entry


Animation
=========

Expand All @@ -37,7 +36,6 @@ To save an animation to disk use `Animation.save` or `Animation.to_html5_video`
See :ref:`ani_writer_classes` below for details about what movie formats are
supported.


``FuncAnimation``
-----------------

Expand All @@ -48,7 +46,6 @@ The inner workings of `FuncAnimation` is more-or-less::
fig.canvas.draw_idle()
fig.canvas.start_event_loop(interval)


with details to handle 'blitting' (to dramatically improve the live
performance), to be non-blocking, not repeatedly start/stop the GUI
event loop, handle repeats, multiple animated axes, and easily save
Expand Down Expand Up @@ -122,54 +119,40 @@ artist at a global scope and let Python sort things out. For example ::
init_func=init, blit=True)
plt.show()


The second method is to us `functools.partial` to 'bind' artists to
function. A third method is to use closures to build up the required
artists and functions. A fourth method is to create a class.




Examples
~~~~~~~~

.. toctree::
:maxdepth: 1

../gallery/animation/animate_decay
../gallery/animation/bayes_update_sgskip
../gallery/animation/double_pendulum_animated_sgskip
../gallery/animation/dynamic_image
../gallery/animation/bayes_update
../gallery/animation/double_pendulum_sgskip
../gallery/animation/histogram
../gallery/animation/rain
../gallery/animation/random_data
../gallery/animation/simple_3danim
../gallery/animation/random_walk
../gallery/animation/simple_anim
../gallery/animation/strip_chart_demo
../gallery/animation/strip_chart
../gallery/animation/unchained

``ArtistAnimation``
-------------------


Examples
~~~~~~~~

.. toctree::
:maxdepth: 1

../gallery/animation/basic_example
../gallery/animation/basic_example_writer_sgskip
../gallery/animation/dynamic_image2



../gallery/animation/dynamic_image

Writer Classes
==============



The provided writers fall into two broad categories: pipe-based and
file-based. The pipe-based writers stream the captured frames over a
pipe to an external process. The pipe-based variants tend to be more
Expand All @@ -179,7 +162,6 @@ performant, but may not work on all systems.
:toctree: _as_gen
:nosignatures:


FFMpegWriter
ImageMagickFileWriter
AVConvWriter
Expand All @@ -196,7 +178,6 @@ slower, these writers can be easier to debug.
ImageMagickWriter
AVConvFileWriter


Fundamentally, a `MovieWriter` provides a way to grab sequential frames
from the same underlying `~matplotlib.figure.Figure` object. The base
class `MovieWriter` implements 3 methods and a context manager. The
Expand All @@ -215,45 +196,39 @@ file to disk. For example ::
moviewriter.grab_frame()
moviewriter.finish()


If using the writer classes directly (not through `Animation.save`), it is strongly encouraged
to use the `~MovieWriter.saving` context manager ::
If using the writer classes directly (not through `Animation.save`), it is
strongly encouraged to use the `~MovieWriter.saving` context manager ::

with moviewriter.saving(fig, 'myfile.mp4', dpi=100):
for j in range(n):
update_figure(n)
moviewriter.grab_frame()


to ensures that setup and cleanup are performed as necessary.

Examples
--------

:ref:`sphx_glr_gallery_animation_moviewriter_sgskip.py`
.. toctree::
:maxdepth: 1

../gallery/animation/frame_grabbing_sgskip

.. _ani_writer_classes:

Helper Classes
==============


Animation Base Classes
----------------------


.. autosummary::
:toctree: _as_gen
:nosignatures:

Animation
TimedAnimation


Custom Animation classes
------------------------

:ref:`sphx_glr_gallery_animation_subplots.py`

Writer Registry
---------------

Expand All @@ -280,7 +255,7 @@ To reduce code duplication base classes
MovieWriter
FileMovieWriter

and mixins are provided
and mixins

.. autosummary::
:toctree: _as_gen
Expand All @@ -290,9 +265,9 @@ and mixins are provided
FFMpegBase
ImageMagickBase

See the source code for how to easily implement new `MovieWriter`
classes.
are provided.

See the source code for how to easily implement new `MovieWriter` classes.

Inheritance Diagrams
====================
Expand Down
4 changes: 2 additions & 2 deletions doc/users/prev_whats_new/whats_new_1.1.rst
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ Ryan May has written a backend-independent framework for creating
animated figures. The :mod:`~matplotlib.animation` module is intended
to replace the backend-specific examples formerly in the
:ref:`examples-index` listings. Examples using the new framework are
in :ref:`animation-examples-index`; see the entrancing :ref:`double
pendulum <sphx_glr_gallery_animation_double_pendulum_animated_sgskip.py>` which uses
in :ref:`animation-examples-index`; see the entrancing :file:`double
pendulum <gallery/animation/double_pendulum_sgskip.py>` which uses
:meth:`matplotlib.animation.Animation.save` to create the movie below.

.. raw:: html
Expand Down
5 changes: 3 additions & 2 deletions examples/animation/animate_decay.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@
Decay
=====

A sinusoidal decay animation.
This example showcases:
- using a generator to drive an animation,
- changing axes limits during an animation.
"""


import numpy as np
import matplotlib.pyplot as plt
import matplotlib.animation as animation
Expand Down
53 changes: 0 additions & 53 deletions examples/animation/basic_example.py

This file was deleted.

54 changes: 0 additions & 54 deletions examples/animation/basic_example_writer_sgskip.py

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,18 @@
distribution should converge.
"""

# update a distribution based on new data.
import math

import numpy as np
import matplotlib.pyplot as plt
import scipy.stats as ss
from matplotlib.animation import FuncAnimation


def beta_pdf(x, a, b):
return (x**(a-1) * (1-x)**(b-1) * math.gamma(a + b)
/ (math.gamma(a) * math.gamma(b)))


class UpdateDist(object):
def __init__(self, ax, prob=0.5):
self.success = 0
Expand Down Expand Up @@ -47,7 +52,7 @@ def __call__(self, i):
# Choose success based on exceed a threshold with a uniform pick
if np.random.rand(1,) < self.prob:
self.success += 1
y = ss.beta.pdf(self.x, self.success + 1, (i - self.success) + 1)
y = beta_pdf(self.x, self.success + 1, (i - self.success) + 1)
self.line.set_data(self.x, y)
return self.line,

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,5 +94,4 @@ def animate(i):
ani = animation.FuncAnimation(fig, animate, np.arange(1, len(y)),
interval=25, blit=True, init_func=init)

# ani.save('double_pendulum.mp4', fps=15)
plt.show()
Loading