File: plot_8_animations.py

package info (click to toggle)
sphinx-gallery 0.19.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 2,336 kB
  • sloc: python: 10,346; makefile: 216; lisp: 15; sh: 11; cpp: 9
file content (29 lines) | stat: -rw-r--r-- 759 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
"""
Matplotlib animation support
============================

Show a Matplotlib animation, which should end up nicely embedded below.

In order to enable support for animations ``'matplotlib_animations'``
must be set to ``True`` in the sphinx gallery
:ref:`configuration <image_scrapers>`.
"""

import matplotlib.animation as animation
import matplotlib.pyplot as plt
import numpy as np

# Adapted from
# https://matplotlib.org/gallery/animation/basic_example.html


def _update_line(num):
    line.set_data(data[..., :num])
    return (line,)


fig, ax = plt.subplots()
data = np.random.RandomState(0).rand(2, 25)
(line,) = ax.plot([], [], "r-")
ax.set(xlim=(0, 1), ylim=(0, 1))
ani = animation.FuncAnimation(fig, _update_line, 25, interval=100, blit=True)