title: How can I get matplotlib's imshow to refresh once every second?
body: <p>Have a sensor that gives me an 8x8 grid of temps that I am to display on a live heatmap. I have made an 8x8 rand to simulate that data. This heatmap should be able to run until I tell it not to run anymore. I'm using python3 and matplotlib to attempt this visualization. </p>
  
  <p>I've tried may ways to make this work, including clearing the screen, turning the plt into a figure, telling show() to not block, etc. You can see many of my attempts in the comments. It either displays once only, or never displays at all (e.g. ion() and plt.show(block=False) never display any data). I've hit my head against a wall for 2 whole work days and I can't figure out why it won't display properly.</p>
  
  <pre><code>import time
  import socket
  import matplotlib.pyplot as plt
  import numpy as np 
  import random
  
  first = True
  randArray = []
  
  #plt.ion()
  plt.show(block=False)
  #fig = plt.figure()
  #str1 = ''.join(str(e) for e in amg.pixels)
  #print (type(str1))
  while True:
      #create a bunch of random numbers
      randArray = np.random.randint(0,50, size=(8,8))
      #print the array, just so I know you're not broken
      for x in randArray:
          print(x)
      #This is my attempt to clear.   
      if (first == False):
          plt.clf()
      first = False
      #basical visualization
      plt.imshow(randArray, cmap='hot', interpolation='nearest')
      plt.draw()
      plt.show()
      #fig.canvas.draw()
      #plt.canvas.draw()
      #plt.display.update
      print("Pausing...")
      time.sleep(5)
  </code></pre>
  
  <p>I expect the code to generate a new set of numbers every 5 seconds, and then refresh the screen with the colors of those new numbers. This should be able to run for hours if I don't interrupt, but the screen never refreshes. </p>
  
  <p>More: I have tried everything listed in the post "How to update a plot in matplotlib?" and everything they do just makes it so that no graph ever populates. The launcher acts like it's going to do something by showing up in the task bar, but then does nothing. I've tried it on a Mac and a Pi, both have the same issue. Maybe it's because that post is 8 years old, and this is python 3 not python 2? Maybe it's because I use imshow() instead of plot()? I haven't figured out how to make their code work on my machine either. </p>
  
  <p>Edit: I've gotten it to work on the raspberry pi thanks to the first commenters recommendations. But now I'm left wondering.... what's wrong with my Mac??</p>