-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathglobplot.py
More file actions
executable file
·86 lines (54 loc) · 1.94 KB
/
globplot.py
File metadata and controls
executable file
·86 lines (54 loc) · 1.94 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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#!/usr/bin/env python
"""DATA PLOTTER
Logan Halstrom
CREATED: 01 OCT 2020
MODIFIED: 01 OCT 2020
quickly plot a glob of files
USAGE:
Command-line: globplot header x y
Add to path: ln -s globplot.py ~/bin/globplot
ToDo:
add a -l --list option so you can manually enter a list of files to plot, rather than glob
"""
import matplotlib.pyplot as plt
import numpy as np
import pandas as pd
import glob
def main(header, x, y, sep=' '):
files = glob.glob('{}*'.format(header))
#case name will be all text after header (minus file extension)
names = [s[len(header):-4] for s in files]
#get rid of leading underscore, if needed
names = [s[1:] if s[0] == '_' else s for s in names]
#title is header without trailing underscore
ttl = header[:-1] if header[-1] == '_' else header
#SORT ALPHABETICALLY
p = pd.DataFrame({'files' : files, 'names' : names})
p = p.sort_values('names')
# #RAINBOW COLORMAP SO YOU KNOW THE ORDER OF PLOTTING
# import matplotlib
# ncolors = 7
# cmap = plt.get_cmap('rainbow')
# colors = [cmap(i) for i in np.linspace(0, 1, ncolors)][::-1]
# matplotlib.rcParams.update({'axes.prop_cycle' : matplotlib.cycler(color=colors)})
#PLOT
plt.figure()
for f, n in zip(p.files,p.names):
df = pd.read_csv(f, sep=sep)
plt.plot(df[x], df[y], label=n)
plt.xlabel(x)
plt.ylabel(y)
plt.title(ttl)
plt.legend()
plt.show()
if __name__ == "__main__":
import argparse
#If called from commandline, perform cleanup in pwd
parser = argparse.ArgumentParser(description='Quickly plot a group of data files ')
parser.add_argument('header', type=str,
help="File header glob (e.g. 'casename*' without the '*' )"
)
parser.add_argument('x', type=str, help="Key for x-axis")
parser.add_argument('y', type=str, help="Key for y-axis")
args = parser.parse_args()
main(header=args.header, x=args.x, y=args.y,)