-
Notifications
You must be signed in to change notification settings - Fork 1
/
plot.py
51 lines (44 loc) · 1.62 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
import argparse
import matplotlib
import matplotlib.pyplot as plt
import os
import pandas as pd
matplotlib.use('TkAgg')
ext = '.xlsx'
parser = argparse.ArgumentParser()
parser.add_argument('--path', required=True)
parser.add_argument('--margin', type=int, choices=[3,5,10], default=3)
args = parser.parse_args()
path = args.path if os.path.splitext(args.path)[1] else f'{args.path}{ext}'
margin = args.margin
def plot(title: str, frame: pd.DataFrame):
plt.figure()
label_ref_x = frame.columns[0]
label_ref_y_high = f'P{100-margin}'
label_ref_y_mid = f'P{50}'
label_ref_y_low = f'P{margin}'
label_x = 'X' if 'X' in frame.columns else label_ref_x
label_y = 'Y'
series_ref_x = frame[label_ref_x]
series_ref_y_high = frame[label_ref_y_high]
series_ref_y_mid = frame[label_ref_y_mid]
series_ref_y_low = frame[label_ref_y_low]
series_x = frame[label_x]
series_y = frame[label_y]
plt.plot(series_ref_x, series_ref_y_high, ':r', label=label_ref_y_high, linewidth=0.7)
plt.plot(series_ref_x, series_ref_y_mid , ':g', label=label_ref_y_mid , linewidth=0.7)
plt.plot(series_ref_x, series_ref_y_low , ':b', label=label_ref_y_low , linewidth=0.7)
plt.plot(series_x, series_y, marker='.', color='grey', label=label_y)
plt.xlabel(label_ref_x)
plt.grid(True)
plt.title(title)
plt.legend()
try:
frames = pd.read_excel(path, sheet_name=None)
for name, frame in frames.items():
plot(name, frame)
plt.show()
except FileNotFoundError:
print(f'File not found at "{path}"')
except KeyError as ex:
print(f'Column "{ex.args[0]}" not found in sheet "{name}"')