-
Notifications
You must be signed in to change notification settings - Fork 1
/
plot_screen.py
58 lines (53 loc) · 1.98 KB
/
plot_screen.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
from PyQt5.QtWidgets import QDialog, QVBoxLayout
from matplotlib.backends.backend_qt5agg import FigureCanvasQTAgg as FigureCanvas
from matplotlib.backends.backend_qt5agg import NavigationToolbar2QT as NavigationToolbar
import matplotlib.pyplot as plt
from util import P
# main window
# which inherits QDialog
class PlotScreen(QDialog):
# constructor
def __init__(self, navigator):
super().__init__()
self.setWindowTitle("Kalman Filter plot")
self.figure = plt.figure()
self.canvas = FigureCanvas(self.figure)
self.toolbar = NavigationToolbar(self.canvas, self)
layout = QVBoxLayout()
layout.addWidget(self.toolbar)
layout.addWidget(self.canvas)
self.setLayout(layout)
def update(self, traces):
self.figure.clear()
ax = self.figure.add_subplot(111)
ax.invert_yaxis()
data = dict()
for target, trace in traces.items():
data[target] = {
"actual": [],
"predict": [],
"observe": []
}
for h in trace.history:
x, y = P(*h['actual'])
data[target]['actual'].append((x, y))
for h in trace.history:
x, y = P(*h['predict'])
data[target]['predict'].append((x, y))
for h in trace.history:
x, y = P(*h['observe'])
data[target]['observe'].append((x, y))
colors = {
'actual': 'r',
'predict': 'g',
'observe': 'b'
}
markers = ['+', '.', 'o', '1']
for type in ['actual', 'predict', 'observe']:
for target in data:
points = data[target][type]
x, y = list(zip(*points))
target_ind = list(data.keys()).index(target)
ax.plot(x, y, label=f"t{target_ind}:{type}", c=colors[type], marker=markers[target_ind])
ax.legend()
self.canvas.draw()