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

Skip to content

Commit 179f95e

Browse files
committed
Update docstring
1 parent 56192f1 commit 179f95e

File tree

2 files changed

+21
-10
lines changed

2 files changed

+21
-10
lines changed

doc/api/animation_api.rst

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,6 @@ artist at a global scope and let Python sort things out. For example ::
113113
import numpy as np
114114
import matplotlib.pyplot as plt
115115
from matplotlib.animation import FuncAnimation
116-
from functools import partial
117116

118117
fig, ax = plt.subplots()
119118
xdata, ydata = [], []
@@ -146,15 +145,15 @@ function. ::
146145
ln, = plt.plot([], [], 'ro')
147146

148147
def init():
149-
ax.set_xlim(0, 2*np.pi)
150-
ax.set_ylim(-1, 1)
151-
return ln,
148+
ax.set_xlim(0, 2*np.pi)
149+
ax.set_ylim(-1, 1)
150+
return ln,
152151

153152
def update(frame, x, y):
154-
x.append(frame)
155-
y.append(np.sin(frame))
156-
ln.set_data(xdata, ydata)
157-
return ln,
153+
x.append(frame)
154+
y.append(np.sin(frame))
155+
ln.set_data(xdata, ydata)
156+
return ln,
158157

159158
xdata, ydata = [], []
160159
ani = FuncAnimation(

lib/matplotlib/animation.py

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1520,12 +1520,24 @@ class FuncAnimation(TimedAnimation):
15201520
func : callable
15211521
The function to call at each frame. The first argument will
15221522
be the next value in *frames*. Any additional positional
1523-
arguments can be supplied via the *fargs* parameter.
1523+
arguments can be supplied using `functools.partial` or via the *fargs*
1524+
parameter.
15241525
15251526
The required signature is::
15261527
15271528
def func(frame, *fargs) -> iterable_of_artists
15281529
1530+
It is often more convenient to provide the arguments using
1531+
`functools.partial`. In this way it is also possible to pass keyword
1532+
arguments. To pass a function with both positional and keyword
1533+
arguments, set all arguments as keyword arguments, just leaving the
1534+
*frame* argument unset::
1535+
1536+
def func(frame, x, *, y=None):
1537+
...
1538+
1539+
ani = FuncAnimation(fig, partial(func, x=1, y='foo'))
1540+
15291541
If ``blit == True``, *func* must return an iterable of all artists
15301542
that were modified or created. This information is used by the blitting
15311543
algorithm to determine which parts of the figure have to be updated.
@@ -1565,7 +1577,7 @@ def init_func() -> iterable_of_artists
15651577
15661578
fargs : tuple or None, optional
15671579
Additional arguments to pass to each call to *func*. Note: the use of
1568-
`functools.partial` is preferred over *fargs*.
1580+
`functools.partial` is preferred over *fargs*. See *func* for details.
15691581
15701582
save_count : int, default: 100
15711583
Fallback for the number of values from *frames* to cache. This is

0 commit comments

Comments
 (0)