Ian Jauslin
summaryrefslogtreecommitdiff
blob: 1e6995a475c173ca61446b1061d702029c8d0ba5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
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()