File tree Expand file tree Collapse file tree 1 file changed +25
-0
lines changed
Expand file tree Collapse file tree 1 file changed +25
-0
lines changed Original file line number Diff line number Diff line change 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 ()
You can’t perform that action at this time.
0 commit comments