Thursday, 15 May 2014

python - Close pre-existing figures in matplotlib when running from eclipse -



python - Close pre-existing figures in matplotlib when running from eclipse -

my question simple: have python script generates figures using matplotlib. every time run it generates new windows figures. how can have script close windows opened previous time ran?

the analogous command in matlab set 'close all' @ origin of matlab script.

i have seen several suggestions like

import matplotlib.pyplot plt plt.close("all")

this solution works if run script python shell, eg using

>>>> execfile("myscript.py")

however, have found doesn't work if run script using eclipse / pydev. how can work in eclipse?

example:

from numpy import * matplotlib.pyplot import * scipy import * close("all") #close open plots - 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()

this should plot ideal waveforms nice 3-phase powerfulness supply.

you can close figure calling matplotlib.pyplot.close, example:

from numpy import * import matplotlib.pyplot plt scipy import * t = linspace(0, 0.1,1000) w = 60*2*pi fig = plt.figure() plt.plot(t,cos(w*t)) plt.plot(t,cos(w*t-2*pi/3)) plt.plot(t,cos(w*t-4*pi/3)) plt.show() plt.close(fig)

you can close open figures calling matplotlib.pyplot.close("all")

python numpy matplotlib pydev matlab-figure

No comments:

Post a Comment