From 179f95e85d07bb4a49f0513f7ee746221eeead3b Mon Sep 17 00:00:00 2001 From: Oscar Gustafsson Date: Fri, 21 Oct 2022 10:23:45 +0200 Subject: [PATCH] Update docstring --- doc/api/animation_api.rst | 15 +++++++-------- lib/matplotlib/animation.py | 16 ++++++++++++++-- 2 files changed, 21 insertions(+), 10 deletions(-) diff --git a/doc/api/animation_api.rst b/doc/api/animation_api.rst index eac200876c2e..282e2f1dcd3d 100644 --- a/doc/api/animation_api.rst +++ b/doc/api/animation_api.rst @@ -113,7 +113,6 @@ artist at a global scope and let Python sort things out. For example :: import numpy as np import matplotlib.pyplot as plt from matplotlib.animation import FuncAnimation - from functools import partial fig, ax = plt.subplots() xdata, ydata = [], [] @@ -146,15 +145,15 @@ function. :: ln, = plt.plot([], [], 'ro') def init(): - ax.set_xlim(0, 2*np.pi) - ax.set_ylim(-1, 1) - return ln, + ax.set_xlim(0, 2*np.pi) + ax.set_ylim(-1, 1) + return ln, def update(frame, x, y): - x.append(frame) - y.append(np.sin(frame)) - ln.set_data(xdata, ydata) - return ln, + x.append(frame) + y.append(np.sin(frame)) + ln.set_data(xdata, ydata) + return ln, xdata, ydata = [], [] ani = FuncAnimation( diff --git a/lib/matplotlib/animation.py b/lib/matplotlib/animation.py index ae2f53904e2e..409576a126b6 100644 --- a/lib/matplotlib/animation.py +++ b/lib/matplotlib/animation.py @@ -1520,12 +1520,24 @@ class FuncAnimation(TimedAnimation): func : callable The function to call at each frame. The first argument will be the next value in *frames*. Any additional positional - arguments can be supplied via the *fargs* parameter. + arguments can be supplied using `functools.partial` or via the *fargs* + parameter. The required signature is:: def func(frame, *fargs) -> iterable_of_artists + It is often more convenient to provide the arguments using + `functools.partial`. In this way it is also possible to pass keyword + arguments. To pass a function with both positional and keyword + arguments, set all arguments as keyword arguments, just leaving the + *frame* argument unset:: + + def func(frame, x, *, y=None): + ... + + ani = FuncAnimation(fig, partial(func, x=1, y='foo')) + If ``blit == True``, *func* must return an iterable of all artists that were modified or created. This information is used by the blitting algorithm to determine which parts of the figure have to be updated. @@ -1565,7 +1577,7 @@ def init_func() -> iterable_of_artists fargs : tuple or None, optional Additional arguments to pass to each call to *func*. Note: the use of - `functools.partial` is preferred over *fargs*. + `functools.partial` is preferred over *fargs*. See *func* for details. save_count : int, default: 100 Fallback for the number of values from *frames* to cache. This is