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

Skip to content

Commit 8fa927f

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 a919d79 commit 8fa927f

17 files changed

+92
-386
lines changed

doc/api/animation_api.rst

Lines changed: 17 additions & 45 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,10 +11,6 @@
1111
:local:
1212
:backlinks: entry
1313

14-
15-
Animation
16-
=========
17-
1814
The easiest way to make a live animation in matplotlib is to use one of the
1915
`Animation` classes.
2016

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

40-
4136
``FuncAnimation``
4237
-----------------
4338

@@ -48,7 +43,6 @@ The inner workings of `FuncAnimation` is more-or-less::
4843
fig.canvas.draw_idle()
4944
fig.canvas.start_event_loop(interval)
5045

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

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

130-
131-
132-
133123
Examples
134124
~~~~~~~~
135125

136126
.. toctree::
137127
:maxdepth: 1
138128

139-
../gallery/animation/animate_decay
140-
../gallery/animation/bayes_update_sgskip
141-
../gallery/animation/double_pendulum_animated_sgskip
129+
../gallery/animation/bayes_update
130+
../gallery/animation/double_pendulum_sgskip
142131
../gallery/animation/dynamic_image
143132
../gallery/animation/histogram
144133
../gallery/animation/rain
145-
../gallery/animation/random_data
146-
../gallery/animation/simple_3danim
134+
../gallery/animation/random_walk
147135
../gallery/animation/simple_anim
148-
../gallery/animation/strip_chart_demo
136+
../gallery/animation/strip_chart
149137
../gallery/animation/unchained
150138

151139
``ArtistAnimation``
152140
-------------------
153141

154-
155142
Examples
156143
~~~~~~~~
157144

158145
.. toctree::
159146
:maxdepth: 1
160147

161-
../gallery/animation/basic_example
162-
../gallery/animation/basic_example_writer_sgskip
163148
../gallery/animation/dynamic_image2
164149

165-
166-
167-
168150
Writer Classes
169151
==============
170152

171-
172-
173153
The provided writers fall into two broad categories: pipe-based and
174154
file-based. The pipe-based writers stream the captured frames over a
175155
pipe to an external process. The pipe-based variants tend to be more
@@ -179,7 +159,6 @@ performant, but may not work on all systems.
179159
:toctree: _as_gen
180160
:nosignatures:
181161

182-
183162
FFMpegWriter
184163
ImageMagickFileWriter
185164
AVConvWriter
@@ -196,7 +175,6 @@ slower, these writers can be easier to debug.
196175
ImageMagickWriter
197176
AVConvFileWriter
198177

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

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

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

227-
228204
to ensures that setup and cleanup are performed as necessary.
229205

206+
Examples
207+
~~~~~~~~
230208

231-
:ref:`sphx_glr_gallery_animation_moviewriter_sgskip.py`
209+
.. toctree::
210+
:maxdepth: 1
232211

212+
../gallery/animation/frame_grabbing_sgskip
233213

234214
.. _ani_writer_classes:
235215

236216
Helper Classes
237217
==============
238218

239-
240219
Animation Base Classes
241220
----------------------
242221

243-
244222
.. autosummary::
245223
:toctree: _as_gen
246224
:nosignatures:
247225

248226
Animation
249227
TimedAnimation
250228

251-
252-
Custom Animation classes
253-
------------------------
254-
255-
:ref:`sphx_glr_gallery_animation_subplots.py`
256-
257229
Writer Registry
258230
---------------
259231

@@ -280,7 +252,7 @@ To reduce code duplication base classes
280252
MovieWriter
281253
FileMovieWriter
282254

283-
and mixins are provided
255+
and mixins
284256

285257
.. autosummary::
286258
:toctree: _as_gen
@@ -290,9 +262,9 @@ and mixins are provided
290262
FFMpegBase
291263
ImageMagickBase
292264

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

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

297269
Inheritance Diagrams
298270
====================

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)