-
Notifications
You must be signed in to change notification settings - Fork 3
/
animate2
executable file
·58 lines (45 loc) · 1.21 KB
/
animate2
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
#! /usr/bin/env python
import numpy as np
import glob
import matplotlib.pyplot as plt
from matplotlib.animation import FuncAnimation
# get the filenames, make sure they are sorted in time
fnames='run1/tab/LinWave*tab'
f = glob.glob(fnames)
f.sort()
print('DEBUG: %s has %d files' % (fnames,len(f)))
def xycols(fname, xcol, ycol):
"""
translate column names into 1-based column numbers
"""
lines = open(fname).readlines()
cols = lines[1].split()
print('DEBUG: ',cols[1:])
ixcol = cols.index(xcol)
iycol = cols.index(ycol)
print('DEBUG: ',ixcol,iycol)
return (ixcol,iycol)
# 1-based columns numbers from the column names
xcol='x1v'
ycol='velx'
(ixcol,iycol) = xycols(f[0],xcol,ycol)
# delay in ms
delay=100
# create the figure and axes objects
fig, ax = plt.subplots()
# function that draws each frame of the animation
def animate(i):
# print(f[i])
d = np.loadtxt(f[i]).T
x = d[ixcol-1]
y = d[iycol-1]
ax.clear()
ax.plot(x, y)
#ax.set_xlim([0,20])
#ax.set_ylim([0,10])
ax.set_title(f[i])
ax.set_xlabel(xcol)
ax.set_ylabel(ycol)
# run the animation
ani = FuncAnimation(fig, animate, frames=len(f), interval=delay, repeat=False)
plt.show()