@@ -108,7 +108,7 @@ this means that the callable objects you pass in must know what
108
108
artists they should be working on. There are several approaches to
109
109
handling this, of varying complexity and encapsulation. The simplest
110
110
approach, which works quite well in the case of a script, is to define the
111
- artist at a global scope and let Python sort things out. For example ::
111
+ artist at a global scope and let Python sort things out. For example::
112
112
113
113
import numpy as np
114
114
import matplotlib.pyplot as plt
@@ -134,31 +134,30 @@ artist at a global scope and let Python sort things out. For example ::
134
134
plt.show()
135
135
136
136
The second method is to use `functools.partial ` to pass arguments to the
137
- function. ::
137
+ function::
138
138
139
139
import numpy as np
140
140
import matplotlib.pyplot as plt
141
141
from matplotlib.animation import FuncAnimation
142
142
from functools import partial
143
143
144
144
fig, ax = plt.subplots()
145
- line1, = plt .plot([], [], 'ro')
145
+ line1, = ax .plot([], [], 'ro')
146
146
147
147
def init():
148
148
ax.set_xlim(0, 2*np.pi)
149
149
ax.set_ylim(-1, 1)
150
- return ln ,
150
+ return line1 ,
151
151
152
152
def update(frame, ln, x, y):
153
153
x.append(frame)
154
154
y.append(np.sin(frame))
155
- ln.set_data(xdata, ydata )
155
+ ln.set_data(x, y )
156
156
return ln,
157
157
158
- xdata, ydata = [], []
159
158
ani = FuncAnimation(
160
- fig, partial(update, ln=line1, x=xdata , y=ydata ),
161
- frames=np.linspace(0, 2 * np.pi, 128),
159
+ fig, partial(update, ln=line1, x=[] , y=[] ),
160
+ frames=np.linspace(0, 2* np.pi, 128),
162
161
init_func=init, blit=True)
163
162
164
163
plt.show()
0 commit comments