title: Close pre-existing figures in matplotlib when running from eclipse
body: <p>My question is simple: I have a python script that generates figures using matplotlib. Every time i run it it generates new windows with figures. How can I have the script close windows that were opened the previous time it ran?</p>
  
  <p>the analogous command in matlab is to put 'close all' at the beginning of your matlab script.</p>
  
  <p>I have seen several suggestions to do something like</p>
  
  <pre><code>import matplotlib.pyplot as plt
  plt.close("all")
  </code></pre>
  
  <p>This solution works if you run your script from the python shell, eg using</p>
  
  <pre><code>&gt;&gt;&gt;&gt; execfile("myScript.py")
  </code></pre>
  
  <p>However, I have found that this doesn't work if I run the script using Eclipse / PyDev. How can I get it to work in Eclipse?</p>
  
  <p>example:</p>
  
  <pre><code>from numpy import *
  from matplotlib.pyplot import *
  from scipy import *
  
  close("all") 
      #close any previously open plots - this doesn't work when running via Eclipse
  
  t = linspace(0, 0.1,1000)
  w = 60*2*pi
  
  figure()
  plot(t,cos(w*t))
  plot(t,cos(w*t-2*pi/3))
  plot(t,cos(w*t-4*pi/3))
  show()
  </code></pre>
  
  <p>This should plot the ideal waveforms for a nice 3-phase power supply.</p>