-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplot.py
executable file
·75 lines (58 loc) · 1.91 KB
/
plot.py
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
#!/usr/bin/python3
import numpy as np
import pandas as pd
from matplotlib import pyplot as plt
import sys
import argparse
def plot_dimensions (num_plots):
# Compute number of rows and columns
# such that there are:
#
# - No more than 9 plots on the page
# - Number of rows differs from number of cols
# by no more than 1
# - There are the fewest unused plots
nrows = 1
ncols = 1
while nrows * ncols < num_plots:
if ncols > nrows:
nrows += 1
elif nrows >= ncols:
ncols += 1
return (nrows, ncols)
def parse_args ():
parser = argparse.ArgumentParser ()
parser.add_argument ("-o", help="Output file")
parser.add_argument ("input", help="Input file, use '-' for stdin")
return parser.parse_args ()
if __name__ == "__main__":
args = parse_args ()
if args.input == '-':
fh = sys.stdin
else:
fh = open (args.input)
data = pd.read_csv (fh, index_col=[0,1]).T
types = sorted (set (data.columns.get_level_values (0)))
events = sorted (set (map (lambda x : x.split ("/")[0],
data[types[0]].index)))
rows, cols = plot_dimensions (len (events))
fig, axes = plt.subplots (rows, cols, figsize=(10, 10))
def sca (idx):
if len (events) > 1:
plt.sca (axes.ravel ()[idx])
for idx, event in enumerate (events):
plot_idx = idx % (rows * cols)
sca (plot_idx)
for tp in types:
subframe = data[tp]
events = subframe.index
sizes = subframe.columns
plt.errorbar (data[tp].T.index,
data[tp].T[event + '/mu'],
data[tp].T[event + '/sigma'],
label=tp)
plt.title (event)
plt.grid (True)
if plot_idx == 0:
plt.legend (loc='best', framealpha=0.0, fontsize=10)
plt.show ()