File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11"""
2- ==============
3- Animation Demo
4- ==============
2+ ================
3+ pyplot animation
4+ ================
55
6- Pyplot animation example .
6+ Generating an animation by calling `~.pyplot.pause` between plotting commands .
77
8- The method shown here is only for very simple, low-performance
9- use. For more demanding applications, look at the animation
10- module and the examples that use it.
8+ The method shown here is only suitable for simple, low-performance use. For
9+ more demanding applications, look at the :mod:`animation` module and the
10+ examples that use it.
11+
12+ Note that calling `time.sleep` instead of `~.pyplot.pause` would *not* work.
1113"""
1214
1315import matplotlib .pyplot as plt
1416import numpy as np
1517
16- x = np .arange (6 )
17- y = np .arange (5 )
18- z = x * y [:, np .newaxis ]
18+ np .random .seed (19680801 )
19+ data = np .random .random ((50 , 50 , 50 ))
1920
20- for i in range (5 ):
21- if i == 0 :
22- p = plt .imshow (z )
23- fig = plt .gcf ()
24- plt .clim () # clamp the color limits
25- plt .title ("Boring slide show" )
26- else :
27- z = z + 2
28- p .set_data (z )
21+ fig , ax = plt .subplots ()
2922
30- print ("step" , i )
31- plt .pause (0.5 )
23+ for i in range (len (data )):
24+ ax .cla ()
25+ ax .imshow (data [i ])
26+ ax .set_title ("frame {}" .format (i ))
27+ # Note that using time.sleep does *not* work here!
28+ plt .pause (0.1 )
You can’t perform that action at this time.
0 commit comments