title: Python - matplotlib.pyplot.imshow won't work in a if//while
body: <p>I'm trying to display an image (a N*P numpy array) in a while loop with imshow but it doesn't seem to work.</p>
  
  <p>When I just use "plt.imshow(image,cmap='gray')" with no indent it works perfectly.</p>
  
  <p>However, when I try to use it from a while loop like</p>
  
  <pre><code>continue=True
  while continue:
      plt.imshow(image,cmap='gray')
      continue=input()
  </code></pre>
  
  <p>or</p>
  
  <pre><code>i=0
  while i&lt;10:
      plt.imshow(image,cmap='gray')
      i+=1
  </code></pre>
  
  <p>the pyplot window just freeze and python crash (same problem with a if).</p>
  
  <p>I don't understand why it does this, does anybody here knows? Thanks alot in advance :)</p>
  
  <p>EDIT : I try to use it like this in my program</p>
  
  <pre><code>import matplotlib.pyplot as plt
  import numpy as np
  import PIL.Image as im
  
  image=np.array(im.open("Blabla.jpg").convert('L')).astype(np.float32)
  
  plt.imshow(image,cmap='gray') #This works -&gt; ONLY when there is not a while after
  
  keepGoin = True #But this doesn't
  while keepGoin:
      plt.imshow(image,cmap='gray')
      keepGoin=input()
  </code></pre>
  
  <p>EDIT 2 :</p>
  
  <p>I made a mistake : it seems that imshow pauses when a while//if is used, even if the while loop is right after the imshow. And when the while loop ends, an image is finally displayed. Maybe using this kind of loop simply pauses the process ?</p>
  
  <p>So I tried to use a secondary function aiming to display the image "out" of the while but it doesn't work either, the result is the same : the pyplot window freeze during the while loop, and the image is displayed right after the loop ends.</p>
  
  <p>EDIT 3 :</p>
  
  <p>So after some more tries, I am pretty sure the problem is not calling imshow from a while but the fact that the loop pauses the execution of pyplot, even if it is called BEFORE the loop (If I call imshow and then use a loop, the pyplot window freeze until the loop ends)</p>
  
  <p>According to some new research I've made, plt.pause could help me but I've an error when I try this.</p>