-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplot_data.py
More file actions
38 lines (33 loc) · 1.15 KB
/
Copy pathplot_data.py
File metadata and controls
38 lines (33 loc) · 1.15 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
import matplotlib.pyplot as plt
import numpy as np
from config import config
class PlotData():
def __init__(self, running_mean_len = config.graph_running_mean):
if config.graph_window:
plt.ion()
self.points = []
self.running_mean = []
self.running_mean_big = []
self.running_mean_len = running_mean_len
self.running_mean_big_len = running_mean_len * 5
def new_data(self, new_point):
self.points.append(new_point)
self.running_mean.append(np.mean(self.points[-self.running_mean_len:]))
self.running_mean_big.append(np.mean(self.points[-self.running_mean_big_len:]))
pass
def clear(self):
plt.ioff()
self.points = []
self.running_mean = []
def graph(self):
if True:
plt.scatter(list(range(len(self.points))), self.points, s=.05, c="y")
plt.plot(self.running_mean, c="b")
plt.plot(self.running_mean_big, c="r")
# plt.autoscale_view()
if config.graph_window:
plt.pause(0.05)
plt.show()
def save(self, name):
self.graph()
plt.savefig(name + ".png")