@@ -103,6 +103,7 @@ artist at a global scope and let Python sort things out. For example ::
103103 import numpy as np
104104 import matplotlib.pyplot as plt
105105 from matplotlib.animation import FuncAnimation
106+ from functools import partial
106107
107108 fig, ax = plt.subplots()
108109 xdata, ydata = [], []
@@ -124,7 +125,35 @@ artist at a global scope and let Python sort things out. For example ::
124125 plt.show()
125126
126127The second method is to use `functools.partial ` to 'bind' artists to
127- function. A third method is to use closures to build up the required
128+ function. ::
129+
130+ import numpy as np
131+ import matplotlib.pyplot as plt
132+ from matplotlib.animation import FuncAnimation
133+
134+ fig, ax = plt.subplots()
135+ xdata, ydata = [], []
136+ ln, = plt.plot([], [], 'ro')
137+
138+ def init():
139+ ax.set_xlim(0, 2*np.pi)
140+ ax.set_ylim(-1, 1)
141+ return ln,
142+
143+ def update(frame):
144+ xdata.append(frame)
145+ ydata.append(np.sin(frame))
146+ ln.set_data(xdata, ydata)
147+ return ln,
148+
149+ ani = FuncAnimation(
150+ fig, partial(update, offset=-0.5),
151+ frames=np.linspace(0, 2 * np.pi, 128),
152+ init_func=init, blit=True)
153+
154+ plt.show()
155+
156+ A third method is to use closures to build up the required
128157artists and functions. A fourth method is to create a class.
129158
130159Examples
0 commit comments