Apr-12-2017, 11:07 AM
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
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()
Moderator Larz60+: Added Python tags. Please do this in the future (see help, BBCODE)