From 774b54d24f985ca64aa082bb77f458d231d43c00 Mon Sep 17 00:00:00 2001 From: Nelle Varoquaux Date: Fri, 21 Oct 2016 15:39:50 -0700 Subject: [PATCH 1/2] DOC MEP12 - converted animation to SG/MEP12 compatible --- examples/animation/animate_decay.py | 9 +++++++++ examples/animation/basic_example.py | 15 +++++++++++++-- examples/animation/basic_example_writer.py | 12 ++++++++++-- examples/animation/bayes_update.py | 11 +++++++++++ 4 files changed, 43 insertions(+), 4 deletions(-) diff --git a/examples/animation/animate_decay.py b/examples/animation/animate_decay.py index 3ddcbdf2408e..271dc6a33392 100644 --- a/examples/animation/animate_decay.py +++ b/examples/animation/animate_decay.py @@ -1,3 +1,12 @@ +""" +===== +Decay +===== + +This example showcases a sinusoidal decay animation. +""" + + import numpy as np import matplotlib.pyplot as plt import matplotlib.animation as animation diff --git a/examples/animation/basic_example.py b/examples/animation/basic_example.py index a0348f4a325a..10971a562069 100644 --- a/examples/animation/basic_example.py +++ b/examples/animation/basic_example.py @@ -1,3 +1,12 @@ +""" +========================= +Simple animation examples +========================= + +This example contains two animations. The first is a random walk plot. the +second is an image animation. +""" + import numpy as np import matplotlib.pyplot as plt import matplotlib.animation as animation @@ -17,7 +26,8 @@ def update_line(num, data, line): plt.title('test') line_ani = animation.FuncAnimation(fig1, update_line, 25, fargs=(data, l), interval=50, blit=True) -#line_ani.save('lines.mp4') + +# To save the animation, use the command: line_ani.save('lines.mp4') fig2 = plt.figure() @@ -30,6 +40,7 @@ def update_line(num, data, line): im_ani = animation.ArtistAnimation(fig2, ims, interval=50, repeat_delay=3000, blit=True) -#im_ani.save('im.mp4', metadata={'artist':'Guido'}) +# To save this second animation with some metadata, use the following command: +# im_ani.save('im.mp4', metadata={'artist':'Guido'}) plt.show() diff --git a/examples/animation/basic_example_writer.py b/examples/animation/basic_example_writer.py index 6f3845dc3f46..31146900f1ca 100644 --- a/examples/animation/basic_example_writer.py +++ b/examples/animation/basic_example_writer.py @@ -1,5 +1,13 @@ -# Same as basic_example, but writes files using a single MovieWriter instance -# without putting on screen +""" +=================== +Saving an animation +=================== + +This example showcases the same animations as `basic_example.py`, but instead +of displaying the animation to the user, it writes to files using a +MovieWriter instance. +""" + # -*- noplot -*- import numpy as np import matplotlib diff --git a/examples/animation/bayes_update.py b/examples/animation/bayes_update.py index 4276e62b864f..a29420d977f6 100644 --- a/examples/animation/bayes_update.py +++ b/examples/animation/bayes_update.py @@ -1,3 +1,14 @@ +""" +================ +The Bayes update +================ + +This animation displays the posterior estimate updates as it is refitted when +new data arrives. +The vertical line represents the theoretical value to which the plotted +distribution should converge. +""" + # update a distribution based on new data. import numpy as np import matplotlib.pyplot as plt From 008e4a4d5ba7fe1b69d6b6d0ae34ffcab998645f Mon Sep 17 00:00:00 2001 From: Nelle Varoquaux Date: Fri, 21 Oct 2016 16:03:39 -0700 Subject: [PATCH 2/2] DOC MEP12 - converted animation to SG/MEP12 compatible --- examples/animation/basic_example.py | 2 +- .../animation/double_pendulum_animated.py | 10 ++++++++- examples/animation/dynamic_image.py | 6 +++++- examples/animation/dynamic_image2.py | 12 +++++++---- examples/animation/histogram.py | 7 ++++++- examples/animation/moviewriter.py | 15 +++++++++---- examples/animation/rain.py | 2 ++ examples/animation/random_data.py | 9 ++++++++ examples/animation/simple_3danim.py | 4 ++++ examples/animation/strip_chart_demo.py | 7 +++++-- examples/animation/subplots.py | 21 ++++++++++++------- examples/animation/unchained.py | 4 ++++ 12 files changed, 78 insertions(+), 21 deletions(-) diff --git a/examples/animation/basic_example.py b/examples/animation/basic_example.py index 10971a562069..4a9c0f6e624d 100644 --- a/examples/animation/basic_example.py +++ b/examples/animation/basic_example.py @@ -3,7 +3,7 @@ Simple animation examples ========================= -This example contains two animations. The first is a random walk plot. the +This example contains two animations. The first is a random walk plot. The second is an image animation. """ diff --git a/examples/animation/double_pendulum_animated.py b/examples/animation/double_pendulum_animated.py index 3b4b48204edb..56af089bbb6f 100644 --- a/examples/animation/double_pendulum_animated.py +++ b/examples/animation/double_pendulum_animated.py @@ -1,3 +1,11 @@ +""" +=========================== +The double pendulum problem +=========================== + +This animation illustrates the double pendulum problem. +""" + # Double pendulum formula translated from the C code at # http://www.physics.usyd.edu.au/~wheat/dpend_html/solve_dpend.c @@ -86,5 +94,5 @@ 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) +# ani.save('double_pendulum.mp4', fps=15) plt.show() diff --git a/examples/animation/dynamic_image.py b/examples/animation/dynamic_image.py index 3dc220254600..cea3327209dc 100644 --- a/examples/animation/dynamic_image.py +++ b/examples/animation/dynamic_image.py @@ -1,5 +1,9 @@ """ +================= An animated image +================= + +This example demonstrates how to animate an image. """ import numpy as np import matplotlib.pyplot as plt @@ -14,7 +18,7 @@ def f(x, y): x = np.linspace(0, 2 * np.pi, 120) y = np.linspace(0, 2 * np.pi, 100).reshape(-1, 1) -im = plt.imshow(f(x, y), cmap=plt.get_cmap('viridis'), animated=True) +im = plt.imshow(f(x, y), animated=True) def updatefig(*args): diff --git a/examples/animation/dynamic_image2.py b/examples/animation/dynamic_image2.py index ca6a48af7588..7fd635b65699 100644 --- a/examples/animation/dynamic_image2.py +++ b/examples/animation/dynamic_image2.py @@ -1,5 +1,10 @@ """ -An animated image +======================================== +An animated image using a list of images +======================================== + +This examples demonstrates how to animate an image from a list of images (or +Artists). """ import numpy as np import matplotlib.pyplot as plt @@ -20,13 +25,12 @@ def f(x, y): for i in range(60): x += np.pi / 15. y += np.pi / 20. - im = plt.imshow(f(x, y), cmap='viridis', animated=True) + im = plt.imshow(f(x, y), animated=True) ims.append([im]) ani = animation.ArtistAnimation(fig, ims, interval=50, blit=True, repeat_delay=1000) -#ani.save('dynamic_images.mp4') - +# ani.save('dynamic_images.mp4') plt.show() diff --git a/examples/animation/histogram.py b/examples/animation/histogram.py index 1ca8c35ac5e5..810a9756d1cc 100644 --- a/examples/animation/histogram.py +++ b/examples/animation/histogram.py @@ -1,6 +1,11 @@ """ +================== +Animated histogram +================== + This example shows how to use a path patch to draw a bunch of -rectangles for an animated histogram +rectangles for an animated histogram. + """ import numpy as np diff --git a/examples/animation/moviewriter.py b/examples/animation/moviewriter.py index 530bbd714f87..afe200ad5746 100644 --- a/examples/animation/moviewriter.py +++ b/examples/animation/moviewriter.py @@ -1,7 +1,14 @@ -# This example uses a MovieWriter directly to grab individual frames and -# write them to a file. This avoids any event loop integration, but has -# the advantage of working with even the Agg backend. This is not recommended -# for use in an interactive setting. +""" +=========== +MovieWriter +=========== + +This example uses a MovieWriter directly to grab individual frames and write +them to a file. This avoids any event loop integration, but has the advantage +of working with even the Agg backend. This is not recommended for use in an +interactive setting. + +""" # -*- noplot -*- import numpy as np diff --git a/examples/animation/rain.py b/examples/animation/rain.py index ee3c7f72d773..db7af8ec8798 100644 --- a/examples/animation/rain.py +++ b/examples/animation/rain.py @@ -1,5 +1,7 @@ """ +=============== Rain simulation +=============== Simulates rain drops on a surface by animating the scale and opacity of 50 scatter points. diff --git a/examples/animation/random_data.py b/examples/animation/random_data.py index d468ffbfce4f..e638768f9ff4 100644 --- a/examples/animation/random_data.py +++ b/examples/animation/random_data.py @@ -1,3 +1,12 @@ +""" +=========== +Random data +=========== + +An animation of random data. + +""" + import numpy as np import matplotlib.pyplot as plt import matplotlib.animation as animation diff --git a/examples/animation/simple_3danim.py b/examples/animation/simple_3danim.py index 60f54625d839..6c3c536d31d5 100644 --- a/examples/animation/simple_3danim.py +++ b/examples/animation/simple_3danim.py @@ -1,4 +1,8 @@ """ +============ +3D animation +============ + A simple example of an animated plot... In 3D! """ import numpy as np diff --git a/examples/animation/strip_chart_demo.py b/examples/animation/strip_chart_demo.py index 0cf0708d76e6..6beeaa99ba07 100644 --- a/examples/animation/strip_chart_demo.py +++ b/examples/animation/strip_chart_demo.py @@ -1,6 +1,9 @@ """ -Emulate an oscilloscope. Requires the animation API introduced in -matplotlib 1.0 SVN. +============ +Oscilloscope +============ + +Emulates an oscilloscope. """ import numpy as np from matplotlib.lines import Line2D diff --git a/examples/animation/subplots.py b/examples/animation/subplots.py index 210fb2dc39e2..9af8296471a1 100644 --- a/examples/animation/subplots.py +++ b/examples/animation/subplots.py @@ -1,14 +1,22 @@ +""" +================= +Animated subplots +================= + +This example uses subclassing, but there is no reason that the proper function +couldn't be set up and then use FuncAnimation. The code is long, but not +really complex. The length is due solely to the fact that there are a total of +9 lines that need to be changed for the animation as well as 3 subplots that +need initial set up. + +""" + import numpy as np import matplotlib.pyplot as plt from matplotlib.lines import Line2D import matplotlib.animation as animation -# This example uses subclassing, but there is no reason that the proper -# function couldn't be set up and then use FuncAnimation. The code is long, but -# not really complex. The length is due solely to the fact that there are a -# total of 9 lines that need to be changed for the animation as well as 3 -# subplots that need initial set up. class SubplotAnimation(animation.TimedAnimation): def __init__(self): fig = plt.figure() @@ -63,7 +71,6 @@ def __init__(self): def _draw_frame(self, framedata): i = framedata head = i - 1 - head_len = 10 head_slice = (self.t > self.t[i] - 1.0) & (self.t < self.t[i]) self.line1.set_data(self.x[:i], self.y[:i]) @@ -93,5 +100,5 @@ def _init_draw(self): l.set_data([], []) ani = SubplotAnimation() -#ani.save('test_sub.mp4') +# ani.save('test_sub.mp4') plt.show() diff --git a/examples/animation/unchained.py b/examples/animation/unchained.py index 71cb69aecd12..c7af48961362 100644 --- a/examples/animation/unchained.py +++ b/examples/animation/unchained.py @@ -1,4 +1,8 @@ """ +======================== +MATPLOTLIB **UNCHAINED** +======================== + Comparative path demonstration of frequency from a fake signal of a pulsar. (mostly known because of the cover for Joy Division's Unknown Pleasures)