FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Clarify how to use keyword arguments in FuncAnimation by oscargus · Pull Request #24139 · matplotlib/matplotlib · GitHub

Repository navigation

Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .py  (1) All 1 file type selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
11 changes: 10 additions & 1 deletion lib/matplotlib/animation.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -1518,7 +1518,8 @@ 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 via the *fargs* parameter. See *fargs* for
how to use `functools.partial` to supply keyword arguments.
Comment on lines +1521 to +1522

story645 Oct 12, 2022 •
edited
Loading

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality
Suggested change
arguments can be supplied via the *fargs* parameter. See *fargs* for
how to use `functools.partial` to supply keyword arguments.
arguments can be supplied using `functools.partial` or via the *fargs* parameter.

Flipped because I think the functools version is preferred. I think it's gonna be clearer to add the information about partial in this section since it's passed in as the func keyword, Maybe after the required signature, something like:

To pass in a function with positional keywords, set func to the partial function::
      
     func = partial(func, frame, **kwargs)


The required signature is::

Expand Down Expand Up @@ -1564,6 +1565,14 @@ def init_func() -> iterable_of_artists
fargs : tuple or None, optional
Additional arguments to pass to each call to *func*.

An option to *fargs* is to use `functools.partial`, with the added

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality
Suggested change
An option to *fargs* is to use `functools.partial`, with the added
An alternative to *fargs* is to use `functools.partial`, with the added

benefit of also supporting keyword arguments. An example is to pass
something like::

partial(func, **kwargs)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Wouldn't you normally have the case that you want to set some kwargs explicitly? Then I suggest to make the example more concrete:

Suggested change
partial(func, **kwargs)
partial(func, my_kwarg='something')

Maye even show a more complete FuncAnimation call to show this fits in.


as *func*.

Comment on lines +1568 to +1575

story645 Oct 12, 2022 •
edited
Loading

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

I think if you move the intro of partial up to func, this can be simplified to

Suggested change
An option to *fargs* is to use `functools.partial`, with the added
benefit of also supporting keyword arguments. An example is to pass
something like::
partial(func, **kwargs)
as *func*.
Passing in `functools.partial` as *func* is preferred to passing in *fargs* and supports keyword arguments. See *func* for an example.

save_count : int, default: 100
Fallback for the number of values from *frames* to cache. This is
only used if the number of frames cannot be inferred from *frames*,
Expand Down

Back | FazBrowse Home | New Git URL