-
Notifications
You must be signed in to change notification settings - Fork 5
/
plotter.py
67 lines (52 loc) · 2 KB
/
plotter.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
61
62
63
64
65
66
67
import matplotlib.pyplot as plt
import numpy as np
from scipy.spatial.transform import Rotation
import seaborn as sns
sns.set(context="paper", style="whitegrid", font_scale=0.8)
class Plotter:
def __init__(self, names):
# Where all the data is stored
self.t = []
self.data = None
self.num_row = 5
self.num_col = 3
self.num_items = len(names)
# Setup figure
self.fig, self.ax = plt.subplots(
self.num_row, self.num_col, figsize=(6, 8), sharex=True
)
# Setup all lines
self.lines = [[[] for _ in range(self.num_row)] for _ in range(len(names))]
for i in range(self.num_row):
for j in range(self.num_col):
for k, n in enumerate(names):
(p,) = self.ax[i, j].plot([], [], label=n)
self.lines[k][i].append(p)
self.ax[-1, 2].legend()
# Add axes labels
titles = ["Position", "Velocity", "RPY", "Bias - Omega", "Bias - Acceleration"]
for i in range(self.num_row):
self.ax[i, 1].set_title(titles[i])
self.fig.tight_layout()
plt.show(block=False)
def add_timestep(self, t, states):
# Keep the time
self.t.append(t)
# Plop our data at the end of the other data
new_state = np.stack([s.data_plot for s in states])
if self.data is None:
self.data = new_state
else:
self.data = np.dstack((self.data, new_state))
def _rot_to_rpy(self, mat):
return Rotation.from_matrix(mat).as_euler("xyz")
def update_plots(self):
# Update all lines
for i in range(self.num_row):
for j in range(self.num_col):
for k in range(self.num_items):
self.lines[k][i][j].set_data(self.t, self.data[k,self.num_col*i+j])
self.ax[i, j].relim()
self.ax[i, j].autoscale_view()
self.fig.canvas.draw()
self.fig.canvas.flush_events()