diff options
Diffstat (limited to 'figs/anim_laser/animate.py')
-rw-r--r-- | figs/anim_laser/animate.py | 103 |
1 files changed, 103 insertions, 0 deletions
diff --git a/figs/anim_laser/animate.py b/figs/anim_laser/animate.py new file mode 100644 index 0000000..1e6995a --- /dev/null +++ b/figs/anim_laser/animate.py @@ -0,0 +1,103 @@ +from matplotlib import pyplot as pl +from matplotlib import animation +import sys + +# read data +# time dependent data +frames=[] +## asymptotic data (located in the first block) +#asym=[] +infile=open(sys.argv[1],'r') +row=[] +for line in infile: + if line=='\n': + frames.append(row) + row=[] + else: + dat=[] + for n in line.split(): + dat.append(float(n)) + row.append(dat) +infile.close() + + +# set up plot +fig = pl.figure() +pl.subplot(211) +axr=fig.gca() +asym_rho, = axr.plot([],[],linewidth=3.5,color='#00FF00') +cn_rho, = axr.plot([],[],color='#FF0000') + +pl.subplot(212) +axJ=fig.gca() +asym_J, = axJ.plot([],[],linewidth=3.5,color='#00FF00') +cn_J, = axJ.plot([],[],color='#FF0000') + +# plot ranges +xmax=0 +maxyr=0 +maxyJ=0 +for frame in frames: + for i in range(len(frame)): + if frame[i][1]>xmax: + xmax=frame[i][1] + if frame[i][2]>maxyr: + maxyr=frame[i][2] + if frame[i][3]>maxyr: + maxyr=frame[i][3] + if frame[i][4]>maxyJ: + maxyJ=frame[i][4] + if frame[i][5]>maxyJ: + maxyJ=frame[i][5] +xmin=0 +minyr=0 +minyJ=0 +for frame in frames: + for i in range(len(frame)): + if frame[i][1]<xmin: + xmin=frame[i][1] + if frame[i][2]<minyr: + minyr=frame[i][2] + if frame[i][3]<minyr: + minyr=frame[i][3] + if frame[i][4]<minyJ: + minyJ=frame[i][4] + if frame[i][5]<minyJ: + minyJ=frame[i][5] + +# animate +def init_plot(): + axr.set_ylim(minyr,maxyr) + axr.set_xlim(xmin,xmax) + axJ.set_ylim(minyJ,maxyJ) + axJ.set_xlim(xmin,xmax) + + axr.vlines(0,minyr,maxyr,linestyles="dotted") + axJ.vlines(0,minyJ,maxyJ,linestyles="dotted") + axJ.hlines(0,xmin,xmax,linestyles="dotted") +def update(frame): + axr.set_title("t=% .3f fs" % (frame[0][0])) + xdata=[] + ydata=[] + asym_data=[] + cn_data=[] + for i in range(len(frame)): + xdata.append(frame[i][1]) + asym_data.append(frame[i][2]) + cn_data.append(frame[i][3]) + asym_rho.set_data(xdata,asym_data) + cn_rho.set_data(xdata,cn_data) + + xdata=[] + ydata=[] + asym_data=[] + cn_data=[] + for i in range(len(frame)): + xdata.append(frame[i][1]) + asym_data.append(frame[i][4]) + cn_data.append(frame[i][5]) + asym_J.set_data(xdata,asym_data) + cn_J.set_data(xdata,cn_data) +anim = animation.FuncAnimation(fig, update, frames=frames, blit=False, interval=100, repeat=True, init_func=init_plot) +#anim.save('laser_schrodinger.m4v', fps=10, extra_args=['-vcodec', 'libx264']) +pl.show() |