title: How to refresh images of axes of Matplotlib figure
body: <p>I want to draw a 3D volume using Matplotlib, slice by slice.
  Mouse scroll to change the index. My program is given below: </p>
  
  <pre><code>#Mouse scroll event.
  def mouse_scroll(event):
  fig = event.canvas.figure
    ax = fig.axes[0]
    if event.button == 'down':
      next_slice(ax)
    fig.canvas.draw()
  
  #Next slice func.
  def previous_slice(ax):
    volume = ax.volume
    ax.index = (ax.index - 1) % volume.shape[0]
    #ax.imshow(volume[ax.index])
    ax.images[0].set_array(volume[ax.index])
  </code></pre>
  
  <p>Figure is initialized in the main function. like:</p>
  
  <pre><code> fig, ax = plt.subplots()
   ax.volume = volume # volume is a 3D data, a 3d np array.
   ax.index = 1
   ax.imshow(volume[ax.index])
   fig.canvas.mpl_connect('scroll_event', mouse_scroll)
  </code></pre>
  
  <p>Everything worked pretty well even I don't understand what is the <code>ax.images</code>. However, problem occurred when I replace the <code>ax.volume</code> with a new volume data. It suddenly stop to render! Debug into the code, the <code>ax.image[0]</code> is correctly set at each event callback. </p>
  
  <p>But, if change the image set_array method to <code>ax.show()</code>. Figure begins to render again. But axes imshow function is really slow comparing to the <code>ax.images[0].set_array()</code> method.</p>
  
  <p>How can I fix this problem? really want to use <code>set_array()</code> method. Thank you very much.</p>
  
  <p>A simple executable script is attached.
   <a href="https://drive.google.com/open?id=1DNZvaHwfCoOpSADmn-WjR5Yz2_T4rCNq" rel="nofollow noreferrer">plot.py@googledrive</a></p>