-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplots.py
47 lines (37 loc) · 1.48 KB
/
plots.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
from matplotlib import pyplot as plt
import numpy as np
import pickle
from typing import List, Dict
from results import Stats
def plot_scatter(
prop, stats_list: List[Stats], entity: str, average: bool = False,
):
if stats_list[0].points.get(prop, None) is None:
raise ValueError(f"Property {prop} not found in stats_list")
scatter_map = {}
for i, stats in enumerate(stats_list):
v = stats.points.get(prop).value
idt = stats.identity
scatter_map.setdefault(idt, []).append(v)
if average:
scatter_map = {k: np.mean(v) for k, v in sorted(scatter_map.items(), key=lambda x: x[0])}
labels = np.arange(len(scatter_map))
plt.scatter(labels, list(scatter_map.values()))
else:
label_scatter = [len(v) for v in scatter_map.values()]
labels = np.repeat(np.arange(len(scatter_map)), label_scatter)
values = np.hstack(list(scatter_map.values()))
plt.scatter(labels, values)
def plot_stream(
prop, stats_list: List[Stats], entity: str,
):
if stats_list[0].streams.get(prop, None) is None:
raise ValueError(f"Property {prop} not found in stats_list")
stream_map = [] # allow for same idt
for i, stats in enumerate(stats_list):
sstat = stats.streams.get(prop)
idt = stats.identity
stream_map.append((idt, sstat.steps, sstat.values))
for idt, steps, values in stream_map:
plt.plot(steps, values, label=idt)
plt.legend()