18
18
# Animation Classes
19
19
# =================
20
20
#
21
- # The process of animation can be thought about in 2 different ways:
21
+ # The process of animation in matplotlib can be thought about in 2 different
22
+ # ways:
22
23
#
23
24
# - :class:`~matplotlib.animation.FuncAnimation`: Generate data for first
24
25
# frame and then modify this data for each frame to create an animated plot.
49
50
# :class:`~matplotlib.animation.FuncAnimation` with different artists.
50
51
51
52
###############################################################################
52
- # Animating :class:`~matplotlib.lines.Line2D`
53
- # ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
53
+ # Animating Lines
54
+ # ^^^^^^^^^^^^^^^
54
55
#
55
56
# `.pyplot.plot` returns a :class:`~matplotlib.lines.Line2D` collection. The
56
57
# data on this collection can be modified by using the
@@ -78,8 +79,8 @@ def update(frame):
78
79
plt .show ()
79
80
80
81
###############################################################################
81
- # Animating :class:`~matplotlib.collections.PathCollection`
82
- # ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
82
+ # Animating Markers
83
+ # ^^^^^^^^^^^^^^^^^
83
84
#
84
85
# `.pyplot.scatter` returns a :class:`~matplotlib.collections.PathCollection`
85
86
# that can similarly be modified by using the
@@ -93,13 +94,15 @@ def update(frame):
93
94
94
95
scat = ax .scatter (np .sin (a * t [0 ] + delta ), np .sin (b * t [0 ]), c = "b" , s = 2 )
95
96
ax .grid ()
96
- ax .set_xlim (- 1 , 1 )
97
- ax .set_ylim (- 1 , 1 )
97
+ ax .set_xlim (- 1.5 , 1.5 )
98
+ ax .set_ylim (- 1.5 , 1.5 )
98
99
99
100
100
101
def update (frame ):
101
- # .set_offsets also resets the entire data for the collection.
102
- # Therefore, we create the entire data in each frame to draw
102
+ # .set_offsets also resets the offset data for the entire collection with
103
+ # the new values. Therefore, to also carry forward the previously
104
+ # calculated information, we use the data from the first to the current
105
+ # frame to set the new offsets.
103
106
x = np .sin (a * t [:frame ] + delta )
104
107
y = np .sin (b * t [:frame ])
105
108
data = np .stack ([x , y ]).T
@@ -112,8 +115,8 @@ def update(frame):
112
115
113
116
114
117
###############################################################################
115
- # Animating :class:`~matplotlib.image.AxesImage`
116
- # ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
118
+ # Animating Images
119
+ # ^^^^^^^^^^^^^^^^
117
120
#
118
121
# When we plot an image using `.pyplot.imshow`, it returns an
119
122
# :class:`~matplotlib.image.AxesImage` object. The data in this object can also
0 commit comments