title: How to play matplotlib animation frame by frame?
body: <p>I use the following code to stop/resume animation (either ArtistAnimation or FuncAnimation works fine):</p>
  
  <pre><code>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)
  </code></pre>
  
  <p>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.</p>
  
  <p>The full code of the program is here (but it is not necessary for answering the question):</p>
  
  <p><a href="https://github.com/tigran123/quantum-infodynamics/blob/master/dynamics/solplay.py" rel="nofollow noreferrer">https://github.com/tigran123/quantum-infodynamics/blob/master/dynamics/solplay.py</a></p>
  
  <p>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.</p>