title: Closing pyplot windows
body: <p>Final Edit: </p>
  
  <p>What I found on the subject of closing pyplot windows is that it really probably shouldn't be done using pyplot.  SRK gives a great example on how to handle plots that will be updated in his answer below.  Also I have stumbled across how to put pyplot plots into a Tkinter window, and Tkinter is much more adept at opening and closing windows than pyplot.  Here <a href="http://matplotlib.sourceforge.net/examples/user_interfaces/embedding_in_tk.html" rel="noreferrer">is how to put a pyplot plot into a Tk window</a> also <a href="https://stackoverflow.com/questions/3554241/how-to-embed-this-matplotlib-code-into-tkinter-canvas">this is a good example</a>.</p>
  
  <p>/Final Edit</p>
  
  <p>I would like to be able to display several plots and then be able to close (remove from screen) them individually from some code input, but I don't know the code input to do this.</p>
  
  <p>Below is what I have tried so far.  I have played around with the position of the show and close commands, but the only real result I have gotten from this is to have one or the other plot not come up, but I have not been able to remove a plot from the screen.  I have been inserting a raw_input() to create pauses.</p>
  
  <p>Edit:  These plots are being called from a Tkinter gui and if there is a better way to do this from that direction I would be glad to hear it.</p>
  
  <p>Any input would be appreciated, thanks.</p>
  
  <pre><code>import matplotlib.pyplot as plt
  
  a = range(0,10)
  b = range(0,20,2)
  c = range(0,30,3)
  d = range(0,40,4)
  
  plot1 = plt.figure()
  plt.plot(a,b, 'r-o')
  
  plt.show()
  
  plt.close()
  
  plot2 = plt.figure()
  plt.plot(c,d, 'b-o')
  
  plt.show()
  plt.close() 
  </code></pre>
  
  <p>Edit Code:  This didn't work either.</p>
  
  <pre><code>plot1 = plt.figure(1)
  plt.plot(a,b, 'r-o')
  
  plot2 = plt.figure(2)
  plt.plot(c,d, 'b-o')
  #plt.close(1)
  #this will prevent plot1 from being displayed
  plt.show()
  plt.close(1)  # or ('all') or (plot1)
  </code></pre>