Re: closing image automatically in for loop , python

2017-04-12 Thread William Ray Wing

> On Apr 12, 2017, at 7:18 AM, Masoud Afshari  wrote:
> 
> Dear all
> 
> I have several *.sfd files which created by a simulation code. I wrote a 
> program containing a for Loop which reads  each time one .sfd file  and plot 
> the requested Parameters. I have two request:
> 
> 1- my Problem is that for Showing successive Images in for Loop I have to 
> Close the Image MANAULLY each time to read next sdf file. can anyone please 
> tell me which command do I have to use so the code Close the Images 
> automatically.
> 

I normally run matplolib in interactive mode, so this may not be quite correct, 
BUT I think you only need to add a call to:

close()

After your call to plt.show()

Bill


> 2- more over, can anyone please tell me how can I create a movie with this 
> code.
> 
> in the following you can see my code
> 
> 
> #
> # in this program, PYTHON reads the reduced files and plot the variables .
>  
>  
> import sys 
> import sdf
> import numpy as np
> import matplotlib.pyplot as plt 
> from matplotlib.font_manager import FontProperties
> fp = FontProperties('Symbola')
>  
> # information from EPOCH input.deck
> nx,ny= 1200, 1600
>  
> xmin=-100e-6
> xmax = 50e-6
> ymin = -100e-6
> ymax = 100e-6
>  
> X =np.linspace(xmin,xmax,nx) #Generate linearly spaced vector. The spacing 
> between the points is (x2-x1)/(n-1).
> Y =np.linspace(ymin,ymax,ny)
>  
> #
> for n in range(0,27):
> nstr = str(n)#.zfill(4)
> #print nstr
>  
> ##
> fig = plt.figure() #plot several figures simultaneously 
> 
> . reading Ex
>  
> filename ="Ex_resample" +'_sdf_'+ str(n)+'.dat'
> with open(filename, 'rb') as f: #read binary file
> data = np.fromfile(f, dtype='float64', count=nx*ny) #float64 for Double 
> precision float numbers
> Ex = np.reshape(data, [ny, nx], order='F')
> #print Ex.max()
>  
> #Display image with scaled colors:
> plt.subplot(222)
> fig1=plt.imshow(Ex, extent=[X.min()*1e6, X.max()*1e6, Y.min()*1e6, 
> Y.max()*1e6], vmin=0, vmax=2e12, cmap='brg', aspect='auto') #cmap='jet', 
> 'nipy_spectral','hot','gist_ncar'
> #plt.suptitle('Ex')
> plt.title('sdf '+ str(n)+ '; Time= ' +str(n*50)+ 'ps',color='green', 
> fontsize=15)
> plt.xlabel('x($\mu$m)')
> plt.ylabel('y($\mu$m)')
> plt.text(40,80,'Ex',color='red', fontsize=15)
> plt.colorbar()
> plt.show()
> #fig.savefig('test.jpg')
> sys.exit()
> -- 
> https://mail.python.org/mailman/listinfo/python-list
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: closing image automatically in for loop , python

2017-04-12 Thread Frank Miles
On Wed, 12 Apr 2017 04:18:45 -0700, Masoud Afshari wrote:

> filename ="Ex_resample" +'_sdf_'+ str(n)+'.dat'
>  with open(filename, 'rb') as f: #read binary file data = np.fromfile(f,
>  dtype='float64', count=nx*ny) #float64 for Double precision float numbers
>  Ex = np.reshape(data, [ny, nx], order='F')
>  #print Ex.max()

Your use of the 'with open(...) as f :' should automatically close access to
filename once beyond that section.  In your posting, the commented-out sections
and garbled spacing would prevent anything useful from happening.

Does that accurately reflect the code you're trying to run?
   -F
-- 
https://mail.python.org/mailman/listinfo/python-list


closing image automatically in for loop , python

2017-04-12 Thread Masoud Afshari
Dear all

 I have several *.sfd files which created by a simulation code. I wrote a 
program containing a for Loop which reads  each time one .sfd file  and plot 
the requested Parameters. I have two request:

 1- my Problem is that for Showing successive Images in for Loop I have to 
Close the Image MANAULLY each time to read next sdf file. can anyone please 
tell me which command do I have to use so the code Close the Images 
automatically.

 2- more over, can anyone please tell me how can I create a movie with this 
code.

 in the following you can see my code


 #
 # in this program, PYTHON reads the reduced files and plot the variables .
 
  
import sys 
 import sdf
 import numpy as np
 import matplotlib.pyplot as plt 
 from matplotlib.font_manager import FontProperties
 fp = FontProperties('Symbola')
 
# information from EPOCH input.deck
 nx,ny= 1200, 1600
 
xmin=-100e-6
 xmax = 50e-6
 ymin = -100e-6
 ymax = 100e-6
 
X =np.linspace(xmin,xmax,nx) #Generate linearly spaced vector. The spacing 
between the points is (x2-x1)/(n-1).
 Y =np.linspace(ymin,ymax,ny)
 
#
for n in range(0,27):
 nstr = str(n)#.zfill(4)
 #print nstr
 
##
fig = plt.figure() #plot several figures simultaneously 

 . reading Ex
 
filename ="Ex_resample" +'_sdf_'+ str(n)+'.dat'
 with open(filename, 'rb') as f: #read binary file
 data = np.fromfile(f, dtype='float64', count=nx*ny) #float64 for Double 
precision float numbers
 Ex = np.reshape(data, [ny, nx], order='F')
 #print Ex.max()
 
#Display image with scaled colors:
 plt.subplot(222)
 fig1=plt.imshow(Ex, extent=[X.min()*1e6, X.max()*1e6, Y.min()*1e6, 
Y.max()*1e6], vmin=0, vmax=2e12, cmap='brg', aspect='auto') #cmap='jet', 
'nipy_spectral','hot','gist_ncar'
 #plt.suptitle('Ex')
 plt.title('sdf '+ str(n)+ '; Time= ' +str(n*50)+ 'ps',color='green', 
fontsize=15)
 plt.xlabel('x($\mu$m)')
 plt.ylabel('y($\mu$m)')
 plt.text(40,80,'Ex',color='red', fontsize=15)
 plt.colorbar()
 plt.show()
 #fig.savefig('test.jpg')
 sys.exit()
-- 
https://mail.python.org/mailman/listinfo/python-list