This would be slightly cumbersome when I change the order / type of arguments my function accepts. I could use functools to attach named parameters to the function update, but it would be nice if FuncAnimation can support this feature.
This would just require adding fkwargs as keyword arguments right? I also noticed that fargs doesn't really have any sort of test written for it, can I give it a go?
or any combination. This is a builtin capability of python and does not require any changes within matplotlib (except maybe that we should encourage this use in the FuncAnimation docs).
You can pass my_update to FuncAnimation, or use it inlined:
from functools import partial
ani = matplotlib.animation.FuncAnimation(
fig,
partial(update, raw_history=raw_history, action_history=action_history, style=style),
frames=len(raw_history), interval=500, repeat=True, repeat_delay=1,
)
The optional positional args will be passed to the callback when it is called. If you want the callback to be called with keyword arguments use functools.partial().
@jeffreypaul15 What would be super helpful would be a note in the FuncAnitamation docstring pointing users at functools.partial and maybe updating / tweaking an existing example or adding a new example that make use of functools.partial.
Activity
anntzer commented on May 29, 2021
I don't particularly like fargs to begin with (I prefer functools.partial), but given that it's here, adding fkwargs seems reasonable.
timhoffm commented on May 29, 2021
So why don‘t we discourage fargs and advertise partial instead, including the note that you can use kwargs there?
anntzer commented on May 29, 2021
That works for me too.
jeffreypaul15 commented on May 31, 2021
This would just require adding fkwargs as keyword arguments right? I also noticed that fargs doesn't really have any sort of test written for it, can I give it a go?
timhoffm commented on May 31, 2021
Um, no. functools.partial lets you create new functions with some parameters bound.
This works for both positional
and keyword argumetns
or any combination. This is a builtin capability of python and does not require any changes within matplotlib (except maybe that we should encourage this use in the FuncAnimation docs).
You can pass my_update to FuncAnimation, or use it inlined:
tacaswell commented on Jun 2, 2021
In defense of saying "use partial" rather than adding support for fkwargs is cite https://docs.python.org/3/library/asyncio-eventloop.html#asyncio.loop.call_later
tacaswell commented on Jun 2, 2021
@jeffreypaul15 What would be super helpful would be a note in the FuncAnitamation docstring pointing users at functools.partial and maybe updating / tweaking an existing example or adding a new example that make use of functools.partial.