title: How to close a python figure by keyboard input?
body: <p>I'm  trying to write a python program that displays a figure for indefinite time and closes it after any keyboard key is pressed.</p>
  
  <p>In fact, the python program should do the same as this Matlab code:</p>
  
  <pre><code>t = 0:0.01:2;
  s = sin(2 * pi * t);
  
  plot(t,s)
  
  pause
  close
  </code></pre>
  
  <p>In python I'm able to plot the figure but nothing happens after the keyboard input.</p>
  
  <pre><code>import numpy as np
  import matplotlib.pyplot as plt
  
  t = np.arange(0.0, 2.0, 0.01)
  s = np.sin(2*np.pi*t)
  
  #plt.ion()
  fig = plt.figure()
  plt.plot(t,s)
  #plt.show()
  plt.draw()
  
  raw_input("PRESS ANY KEY TO CONTINUE.")
  plt.close(fig)
  </code></pre>
  
  <p>So far I observed that <code>plt.close(fig)</code> does not do anything in conjunction with <code>plt.show()</code>. However, when I use <code>plt.draw()</code> instead, <code>plt.close(fig)</code> is closing the figure. Yet, when I add <code>raw_input("PRESS ANY KEY TO CONTINUE.")</code> into my program, the figure does not appear at all.</p>
  
  <p>What am I doing wrong?</p>
  
  <p>I also tried experimenting with <code>plt.ion()</code>, but without success.</p>