Clarify how to use keyword arguments in FuncAnimation#24139
Clarify how to use keyword arguments in FuncAnimation#24139oscargus wants to merge 1 commit intomatplotlib:mainfrom
Conversation
| 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 |
There was a problem hiding this comment.
| An option to *fargs* is to use `functools.partial`, with the added | |
| An alternative to *fargs* is to use `functools.partial`, with the added |
| arguments can be supplied via the *fargs* parameter. See *fargs* for | ||
| how to use `functools.partial` to supply keyword arguments. |
There was a problem hiding this comment.
| 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)
| 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*. | ||
|
|
There was a problem hiding this comment.
I think if you move the intro of partial up to func, this can be simplified to
| 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. |
| benefit of also supporting keyword arguments. An example is to pass | ||
| something like:: | ||
|
|
||
| partial(func, **kwargs) |
There was a problem hiding this comment.
Wouldn't you normally have the case that you want to set some kwargs explicitly? Then I suggest to make the example more concrete:
| partial(func, **kwargs) | |
| partial(func, my_kwarg='something') |
Maye even show a more complete FuncAnimation call to show this fits in.
|
There is also #20358 which solves the same issue. I'll have a look and may go for extending that instead (the importance of linking PRs to issues...). |
PR Summary
Closes #20326
I didn't find a good animation example to modify...
PR Checklist
Tests and Styling
pytestpasses).flake8-docstringsand runflake8 --docstring-convention=all).Documentation
doc/users/next_whats_new/(follow instructions in README.rst there).doc/api/next_api_changes/(follow instructions in README.rst there).