Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit b638f92

Browse files
committed
Cleanup animation examples
I thought that the animation examples section was a bit of an unstructured mess so I tried to reorganize it somewhat. The new list of examples is simple examples =============== animation_demo: plt.pause example simple_anim: FuncAnimation example dynamic_image: FuncAnimation example dynamic_image2: ArtistAnimation example intermediate examples ===================== strip_chart: FuncAnimation example advanced examples ================= histogram: animating a composite artist (namely, a histogram) nice examples ============= bayes: FuncAnimation example double_pendulum: FuncAnimation example, skipped as needing scipy random_walk (renamed from simple_3danim): FuncAnimation example rain: FuncAnimation example unchained: FuncAnimation example movie writing ============= frame_grabbing_sgskip (renamed from moviewriter_sgskip.py) removed ======= animate_decay: overlaps with simple_anim basic_example: equivalent to {simple_anim + dynamic_image2} basic_example_writer_sgskip: split as comments to simple_anim/dynamic_image/dynamic_image2 random_data: overlaps with simple_anim, though using a generator subplots: relies on subclassing private attributes of TimedAnimation, would better be replaced by a FuncAnimation example, overly complex
1 parent 4f9458d commit b638f92

18 files changed

+94
-385
lines changed

doc/api/animation_api.rst

Lines changed: 17 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
======================
2-
``animation`` module
3-
======================
1+
*********
2+
animation
3+
*********
44

55
.. automodule:: matplotlib.animation
66
:no-members:
@@ -11,7 +11,6 @@
1111
:local:
1212
:backlinks: entry
1313

14-
1514
Animation
1615
=========
1716

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

40-
4139
``FuncAnimation``
4240
-----------------
4341

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

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

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

130-
131-
132-
133126
Examples
134127
~~~~~~~~
135128

136129
.. toctree::
137130
:maxdepth: 1
138131

139-
../gallery/animation/animate_decay
140-
../gallery/animation/bayes_update_sgskip
141-
../gallery/animation/double_pendulum_animated_sgskip
132+
../gallery/animation/bayes_update
133+
../gallery/animation/double_pendulum_sgskip
142134
../gallery/animation/dynamic_image
143135
../gallery/animation/histogram
144136
../gallery/animation/rain
145-
../gallery/animation/random_data
146-
../gallery/animation/simple_3danim
137+
../gallery/animation/random_walk
147138
../gallery/animation/simple_anim
148-
../gallery/animation/strip_chart_demo
139+
../gallery/animation/strip_chart
149140
../gallery/animation/unchained
150141

151142
``ArtistAnimation``
152143
-------------------
153144

154-
155145
Examples
156146
~~~~~~~~
157147

158148
.. toctree::
159149
:maxdepth: 1
160150

161-
../gallery/animation/basic_example
162-
../gallery/animation/basic_example_writer_sgskip
163151
../gallery/animation/dynamic_image2
164152

165-
166-
167-
168153
Writer Classes
169154
==============
170155

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

182-
183165
FFMpegWriter
184166
ImageMagickFileWriter
185167
AVConvWriter
@@ -196,7 +178,6 @@ slower, these writers can be easier to debug.
196178
ImageMagickWriter
197179
AVConvFileWriter
198180

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

218-
219-
If using the writer classes directly (not through `Animation.save`), it is strongly encouraged
220-
to use the `~MovieWriter.saving` context manager ::
199+
If using the writer classes directly (not through `Animation.save`), it is
200+
strongly encouraged to use the `~MovieWriter.saving` context manager ::
221201

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

227-
228207
to ensures that setup and cleanup are performed as necessary.
229208

209+
Examples
210+
--------
230211

231-
:ref:`sphx_glr_gallery_animation_moviewriter_sgskip.py`
212+
.. toctree::
213+
:maxdepth: 1
232214

215+
../gallery/animation/frame_grabbing_sgskip
233216

234217
.. _ani_writer_classes:
235218

236219
Helper Classes
237220
==============
238221

239-
240222
Animation Base Classes
241223
----------------------
242224

243-
244225
.. autosummary::
245226
:toctree: _as_gen
246227
:nosignatures:
247228

248229
Animation
249230
TimedAnimation
250231

251-
252-
Custom Animation classes
253-
------------------------
254-
255-
:ref:`sphx_glr_gallery_animation_subplots.py`
256-
257232
Writer Registry
258233
---------------
259234

@@ -280,7 +255,7 @@ To reduce code duplication base classes
280255
MovieWriter
281256
FileMovieWriter
282257

283-
and mixins are provided
258+
and mixins
284259

285260
.. autosummary::
286261
:toctree: _as_gen
@@ -290,9 +265,9 @@ and mixins are provided
290265
FFMpegBase
291266
ImageMagickBase
292267

293-
See the source code for how to easily implement new `MovieWriter`
294-
classes.
268+
are provided.
295269

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

297272
Inheritance Diagrams
298273
====================

doc/users/prev_whats_new/whats_new_1.1.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@ Ryan May has written a backend-independent framework for creating
3535
animated figures. The :mod:`~matplotlib.animation` module is intended
3636
to replace the backend-specific examples formerly in the
3737
:ref:`examples-index` listings. Examples using the new framework are
38-
in :ref:`animation-examples-index`; see the entrancing :ref:`double
39-
pendulum <sphx_glr_gallery_animation_double_pendulum_animated_sgskip.py>` which uses
38+
in :ref:`animation-examples-index`; see the entrancing :file:`double
39+
pendulum <gallery/animation/double_pendulum_sgskip.py>` which uses
4040
:meth:`matplotlib.animation.Animation.save` to create the movie below.
4141

4242
.. raw:: html

examples/animation/animate_decay.py

Lines changed: 0 additions & 53 deletions
This file was deleted.

examples/animation/basic_example.py

Lines changed: 0 additions & 53 deletions
This file was deleted.

examples/animation/basic_example_writer_sgskip.py

Lines changed: 0 additions & 54 deletions
This file was deleted.

examples/animation/bayes_update_sgskip.py renamed to examples/animation/bayes_update.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,18 @@
99
distribution should converge.
1010
"""
1111

12-
# update a distribution based on new data.
12+
import math
13+
1314
import numpy as np
1415
import matplotlib.pyplot as plt
15-
import scipy.stats as ss
1616
from matplotlib.animation import FuncAnimation
1717

1818

19+
def beta_pdf(x, a, b):
20+
return (x**(a-1) * (1-x)**(b-1) * math.gamma(a + b)
21+
/ (math.gamma(a) * math.gamma(b)))
22+
23+
1924
class UpdateDist(object):
2025
def __init__(self, ax, prob=0.5):
2126
self.success = 0
@@ -47,7 +52,7 @@ def __call__(self, i):
4752
# Choose success based on exceed a threshold with a uniform pick
4853
if np.random.rand(1,) < self.prob:
4954
self.success += 1
50-
y = ss.beta.pdf(self.x, self.success + 1, (i - self.success) + 1)
55+
y = beta_pdf(self.x, self.success + 1, (i - self.success) + 1)
5156
self.line.set_data(self.x, y)
5257
return self.line,
5358

examples/animation/double_pendulum_animated_sgskip.py renamed to examples/animation/double_pendulum_sgskip.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,5 +94,4 @@ def animate(i):
9494
ani = animation.FuncAnimation(fig, animate, np.arange(1, len(y)),
9595
interval=25, blit=True, init_func=init)
9696

97-
# ani.save('double_pendulum.mp4', fps=15)
9897
plt.show()

0 commit comments

Comments
 (0)