Skip to content

Commit 9830a70

Browse files
author
Jonathan Rocher
committed
Adding an animation in MPL simply using multiple calls to show.
1 parent 37789f0 commit 9830a70

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

matplotlib/interactive_plotting.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
""" Demo of making an animation with matplotlib. This is the simplest possible
2+
option: just redrawing different things on the same figure at a given interval.
3+
4+
Alternatives to this require a timer or an instance of the animation subpackage
5+
in MPL.
6+
7+
Note: this should be run outside of ipython, to avoid interference.
8+
"""
9+
import numpy as np
10+
from time import sleep
11+
from matplotlib.pyplot import show, ion, figure
12+
# Allow show() to be non-blocking
13+
ion()
14+
15+
x = np.linspace(0, 4*np.pi)
16+
fig = figure()
17+
18+
for phase in np.linspace(0, 2*np.pi):
19+
y = np.sin(x+phase)
20+
ax = fig.add_subplot(1,1,1)
21+
line, = ax.plot(x, y)
22+
# Force a redraw
23+
ax.figure.canvas.draw()
24+
sleep(0.5)
25+
show()

0 commit comments

Comments
 (0)