I use the following code to stop/resume animation (either ArtistAnimation or FuncAnimation works fine):
def keypress(event):
global anim_running
if event.key == ' ': # SPACE: pause and resume animation
if anim and anim.event_source:
anim.event_source.stop() if anim_running else anim.event_source.start()
anim_running ^= True
fig.canvas.mpl_connect('key_press_event', keypress)
Now, what I would like to do is, with the animation stopped I would like to press some key (e.g. 't') and see the next frame and with some other key (e.g. 'T') see the previous frame. I.e. to be able to manually step frame by frame.
The full code of the program is here (but it is not necessary for answering the question):
https://github.com/tigran123/quantum-infodynamics/blob/master/dynamics/solplay.py
I realise, of course that one could completely ignore the 'k' argument of animate(k) and maintain my own global frame number which could be controlled via keyboard handler. But this would waste a lot of CPU (i.e. keep re-rendering the same frame) and I thought there must be a better way by manipulating the animation object directly.