-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplotdatfile.py
More file actions
72 lines (58 loc) · 1.92 KB
/
Copy pathplotdatfile.py
File metadata and controls
72 lines (58 loc) · 1.92 KB
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
import os, sys
import numpy as np
import matplotlib.pyplot as plt
def dat_file_scrape(full_file_path, header_skip=7, xcol=0, ycol=2):
print full_file_path
x, y = [], []
f = open(full_file_path, 'rU')
for line in f.readlines()[header_skip:]:
entry = line.split()
x.append(float(entry[xcol]))
y.append(float(entry[ycol]))
x = np.array(x)
y = np.array(y)
return x, y
def get_files(path='.', suffix='dat'):
dats_list = [x for x in os.listdir(path) if x.endswith(suffix)]
dats_list = sorted(dats_list)
dat_dict = {}
for i, fid in enumerate(dats_list):
dat_dict[i] = fid
print i, fid
dat_choice = raw_input('Choose your dat, dats separated by a space or "all": ').rstrip(' ')
if 'all' in dat_choice:
dat_fids_list = dats_list
else:
dat_fids_list = [dat_dict[int(x)] for x in dat_choice.split(' ')]
return dat_fids_list
def main(args):
for arg in args:
print arg
#path = get_directory
dat_fids_list = get_files()
fig = plt.figure()
fig.subplots_adjust(left = 0.05,
bottom = 0.05,
right = 0.95,
top = 0.95,
wspace = 0.00,
hspace = 0.00)
num_colors = len(dat_fids_list)
cm = plt.get_cmap('gist_rainbow')
ax = fig.add_subplot(111, axisbg='k')
ax.set_color_cycle([cm((1.0 * i) / num_colors) for i in range(num_colors)])
for fid in dat_fids_list:
x, y = dat_file_scrape(fid)
ax.plot(x, y, linewidth=2, label=fid)
plt.xlim(x.min(), x.max())
plt.ylim(y.min(), y.max())
plt.title('Fancy Title')
plt.xlabel('xlabel')
plt.ylabel('ylabel')
leg = plt.legend(loc='lower left', title='legend', fancybox=True)
frame = leg.get_frame()
frame.set_facecolor('beige')
plt.show()
if __name__ == '__main__':
main(sys.argv)
plt.close()