-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplot_curves.py
60 lines (52 loc) · 2.38 KB
/
plot_curves.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
import json
import yaml
import matplotlib
matplotlib.use('Agg')
import matplotlib.pyplot as plt
def plot_curves(curves, out_pdf, selected_indices=None, selected_names=None):
pts_per_inch = 72.
if 'page_setup' in curves:
plt.figure(figsize=(curves['page_setup']['width']/pts_per_inch, curves['page_setup']['height']/pts_per_inch))
plt.xscale('log' if curves['axis_setup']['x']['log'] else 'linear')
plt.yscale('log' if curves['axis_setup']['y']['log'] else 'linear')
for idx, curve in enumerate(curves['curves']):
if selected_indices and idx not in selected_indices: continue
if selected_names and curve['name'] not in selected_names: continue
if 'y_up' not in curve:
color = curve['stroking_color']
plt.plot(curve['x'], curve['y'], linewidth=curve['linewidth'], color=color)
else:
color = curve['non_stroking_color']
if not color:
color = curve['stroking_color']
plt.fill_between(curve['x'], curve['y_up'], curve['y_down'], color=color)
print(f'{idx}: name={curve["name"]}, color={color}')
if len(curves['axis_setup']['x']['range']) == 2:
plt.xlim(curves['axis_setup']['x']['range'])
if len(curves['axis_setup']['y']['range']) == 2:
plt.ylim(curves['axis_setup']['y']['range'])
plt.savefig(out_pdf, bbox_inches='tight')
if __name__ == "__main__":
import argparse
parser = argparse.ArgumentParser(description='Plot extracted curves.')
parser.add_argument('--out-pdf', required=True, type=str, default=None,
help="output pdf file produced from the extracted data (to check the result)")
parser.add_argument('--idx', required=False, type=str, default=None,
help="comma separated list of curve indices to plot")
parser.add_argument('--name', required=False, type=str, default=None,
help="comma separated list of curve names to plot")
parser.add_argument('input', type=str, nargs=1, help="input file in json or yaml format")
args = parser.parse_args()
input = args.input[0]
with open(input, 'r') as f:
if input.endswith('.json'):
curves = json.load(f)
else:
curves = yaml.safe_load(f)
selected_indices = None
if args.idx:
selected_indices = [int(idx) for idx in args.idx.split(',')]
selected_names = None
if args.name:
selected_names = args.name.split(',')
plot_curves(curves, args.out_pdf, selected_indices, selected_names)