Skip to content

Commit 00ae164

Browse files
authored
Merge pull request #7329 from NelleV/MEP12_animation
DOC: converted animation to SG/MEP12 compatible
2 parents 1f38ea6 + 008e4a4 commit 00ae164

15 files changed

+120
-24
lines changed

examples/animation/animate_decay.py

+9
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
1+
"""
2+
=====
3+
Decay
4+
=====
5+
6+
This example showcases a sinusoidal decay animation.
7+
"""
8+
9+
110
import numpy as np
211
import matplotlib.pyplot as plt
312
import matplotlib.animation as animation

examples/animation/basic_example.py

+13-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
1+
"""
2+
=========================
3+
Simple animation examples
4+
=========================
5+
6+
This example contains two animations. The first is a random walk plot. The
7+
second is an image animation.
8+
"""
9+
110
import numpy as np
211
import matplotlib.pyplot as plt
312
import matplotlib.animation as animation
@@ -17,7 +26,8 @@ def update_line(num, data, line):
1726
plt.title('test')
1827
line_ani = animation.FuncAnimation(fig1, update_line, 25, fargs=(data, l),
1928
interval=50, blit=True)
20-
#line_ani.save('lines.mp4')
29+
30+
# To save the animation, use the command: line_ani.save('lines.mp4')
2131

2232
fig2 = plt.figure()
2333

@@ -30,6 +40,7 @@ def update_line(num, data, line):
3040

3141
im_ani = animation.ArtistAnimation(fig2, ims, interval=50, repeat_delay=3000,
3242
blit=True)
33-
#im_ani.save('im.mp4', metadata={'artist':'Guido'})
43+
# To save this second animation with some metadata, use the following command:
44+
# im_ani.save('im.mp4', metadata={'artist':'Guido'})
3445

3546
plt.show()

examples/animation/basic_example_writer.py

+10-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
1-
# Same as basic_example, but writes files using a single MovieWriter instance
2-
# without putting on screen
1+
"""
2+
===================
3+
Saving an animation
4+
===================
5+
6+
This example showcases the same animations as `basic_example.py`, but instead
7+
of displaying the animation to the user, it writes to files using a
8+
MovieWriter instance.
9+
"""
10+
311
# -*- noplot -*-
412
import numpy as np
513
import matplotlib

examples/animation/bayes_update.py

+11
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,14 @@
1+
"""
2+
================
3+
The Bayes update
4+
================
5+
6+
This animation displays the posterior estimate updates as it is refitted when
7+
new data arrives.
8+
The vertical line represents the theoretical value to which the plotted
9+
distribution should converge.
10+
"""
11+
112
# update a distribution based on new data.
213
import numpy as np
314
import matplotlib.pyplot as plt

examples/animation/double_pendulum_animated.py

+9-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
"""
2+
===========================
3+
The double pendulum problem
4+
===========================
5+
6+
This animation illustrates the double pendulum problem.
7+
"""
8+
19
# Double pendulum formula translated from the C code at
210
# http://www.physics.usyd.edu.au/~wheat/dpend_html/solve_dpend.c
311

@@ -86,5 +94,5 @@ def animate(i):
8694
ani = animation.FuncAnimation(fig, animate, np.arange(1, len(y)),
8795
interval=25, blit=True, init_func=init)
8896

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

examples/animation/dynamic_image.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
"""
2+
=================
23
An animated image
4+
=================
5+
6+
This example demonstrates how to animate an image.
37
"""
48
import numpy as np
59
import matplotlib.pyplot as plt
@@ -14,7 +18,7 @@ def f(x, y):
1418
x = np.linspace(0, 2 * np.pi, 120)
1519
y = np.linspace(0, 2 * np.pi, 100).reshape(-1, 1)
1620

17-
im = plt.imshow(f(x, y), cmap=plt.get_cmap('viridis'), animated=True)
21+
im = plt.imshow(f(x, y), animated=True)
1822

1923

2024
def updatefig(*args):

examples/animation/dynamic_image2.py

+8-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
"""
2-
An animated image
2+
========================================
3+
An animated image using a list of images
4+
========================================
5+
6+
This examples demonstrates how to animate an image from a list of images (or
7+
Artists).
38
"""
49
import numpy as np
510
import matplotlib.pyplot as plt
@@ -20,13 +25,12 @@ def f(x, y):
2025
for i in range(60):
2126
x += np.pi / 15.
2227
y += np.pi / 20.
23-
im = plt.imshow(f(x, y), cmap='viridis', animated=True)
28+
im = plt.imshow(f(x, y), animated=True)
2429
ims.append([im])
2530

2631
ani = animation.ArtistAnimation(fig, ims, interval=50, blit=True,
2732
repeat_delay=1000)
2833

29-
#ani.save('dynamic_images.mp4')
30-
34+
# ani.save('dynamic_images.mp4')
3135

3236
plt.show()

examples/animation/histogram.py

+6-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
"""
2+
==================
3+
Animated histogram
4+
==================
5+
26
This example shows how to use a path patch to draw a bunch of
3-
rectangles for an animated histogram
7+
rectangles for an animated histogram.
8+
49
"""
510
import numpy as np
611

examples/animation/moviewriter.py

+11-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,14 @@
1-
# This example uses a MovieWriter directly to grab individual frames and
2-
# write them to a file. This avoids any event loop integration, but has
3-
# the advantage of working with even the Agg backend. This is not recommended
4-
# for use in an interactive setting.
1+
"""
2+
===========
3+
MovieWriter
4+
===========
5+
6+
This example uses a MovieWriter directly to grab individual frames and write
7+
them to a file. This avoids any event loop integration, but has the advantage
8+
of working with even the Agg backend. This is not recommended for use in an
9+
interactive setting.
10+
11+
"""
512
# -*- noplot -*-
613

714
import numpy as np

examples/animation/rain.py

+2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
"""
2+
===============
23
Rain simulation
4+
===============
35
46
Simulates rain drops on a surface by animating the scale and opacity
57
of 50 scatter points.

examples/animation/random_data.py

+9
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
1+
"""
2+
===========
3+
Random data
4+
===========
5+
6+
An animation of random data.
7+
8+
"""
9+
110
import numpy as np
211
import matplotlib.pyplot as plt
312
import matplotlib.animation as animation

examples/animation/simple_3danim.py

+4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
"""
2+
============
3+
3D animation
4+
============
5+
26
A simple example of an animated plot... In 3D!
37
"""
48
import numpy as np

examples/animation/strip_chart_demo.py

+5-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
"""
2-
Emulate an oscilloscope. Requires the animation API introduced in
3-
matplotlib 1.0 SVN.
2+
============
3+
Oscilloscope
4+
============
5+
6+
Emulates an oscilloscope.
47
"""
58
import numpy as np
69
from matplotlib.lines import Line2D

examples/animation/subplots.py

+14-7
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,22 @@
1+
"""
2+
=================
3+
Animated subplots
4+
=================
5+
6+
This example uses subclassing, but there is no reason that the proper function
7+
couldn't be set up and then use FuncAnimation. The code is long, but not
8+
really complex. The length is due solely to the fact that there are a total of
9+
9 lines that need to be changed for the animation as well as 3 subplots that
10+
need initial set up.
11+
12+
"""
13+
114
import numpy as np
215
import matplotlib.pyplot as plt
316
from matplotlib.lines import Line2D
417
import matplotlib.animation as animation
518

619

7-
# This example uses subclassing, but there is no reason that the proper
8-
# function couldn't be set up and then use FuncAnimation. The code is long, but
9-
# not really complex. The length is due solely to the fact that there are a
10-
# total of 9 lines that need to be changed for the animation as well as 3
11-
# subplots that need initial set up.
1220
class SubplotAnimation(animation.TimedAnimation):
1321
def __init__(self):
1422
fig = plt.figure()
@@ -63,7 +71,6 @@ def __init__(self):
6371
def _draw_frame(self, framedata):
6472
i = framedata
6573
head = i - 1
66-
head_len = 10
6774
head_slice = (self.t > self.t[i] - 1.0) & (self.t < self.t[i])
6875

6976
self.line1.set_data(self.x[:i], self.y[:i])
@@ -93,5 +100,5 @@ def _init_draw(self):
93100
l.set_data([], [])
94101

95102
ani = SubplotAnimation()
96-
#ani.save('test_sub.mp4')
103+
# ani.save('test_sub.mp4')
97104
plt.show()

examples/animation/unchained.py

+4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
"""
2+
========================
3+
MATPLOTLIB **UNCHAINED**
4+
========================
5+
26
Comparative path demonstration of frequency from a fake signal of a pulsar.
37
(mostly known because of the cover for Joy Division's Unknown Pleasures)
48

0 commit comments

Comments
 (0)