Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit d97cc32

Browse files
committed
Fix partial example
1 parent cb0a6a0 commit d97cc32

File tree

1 file changed

+7
-8
lines changed

1 file changed

+7
-8
lines changed

doc/api/animation_api.rst

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ this means that the callable objects you pass in must know what
108108
artists they should be working on. There are several approaches to
109109
handling this, of varying complexity and encapsulation. The simplest
110110
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::
112112

113113
import numpy as np
114114
import matplotlib.pyplot as plt
@@ -134,31 +134,30 @@ artist at a global scope and let Python sort things out. For example ::
134134
plt.show()
135135

136136
The second method is to use `functools.partial` to pass arguments to the
137-
function. ::
137+
function::
138138

139139
import numpy as np
140140
import matplotlib.pyplot as plt
141141
from matplotlib.animation import FuncAnimation
142142
from functools import partial
143143

144144
fig, ax = plt.subplots()
145-
line1, = plt.plot([], [], 'ro')
145+
line1, = ax.plot([], [], 'ro')
146146

147147
def init():
148148
ax.set_xlim(0, 2*np.pi)
149149
ax.set_ylim(-1, 1)
150-
return ln,
150+
return line1,
151151

152152
def update(frame, ln, x, y):
153153
x.append(frame)
154154
y.append(np.sin(frame))
155-
ln.set_data(xdata, ydata)
155+
ln.set_data(x, y)
156156
return ln,
157157

158-
xdata, ydata = [], []
159158
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),
162161
init_func=init, blit=True)
163162

164163
plt.show()

0 commit comments

Comments
 (0)