-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathxyplot.py
More file actions
72 lines (60 loc) · 2.23 KB
/
xyplot.py
File metadata and controls
72 lines (60 loc) · 2.23 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
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
68
69
70
71
72
from abc import abstractmethod
from typing import List, Any, Dict, Tuple, FrozenSet # need to not alias OrderedDict
from collections import OrderedDict
import csv
import numpy as np # type: ignore
import matplotlib.pyplot as plt # type: ignore
if __name__ == '__main__':
import argparse
parser = argparse.ArgumentParser(description='CSV Telemetry / Logger Visualizer')
parser.add_argument('filename',
help='filename of CSV to open')
parser.add_argument('--skip_data_rows', type=int, default=0,
help='data rows (after the first header row) to skip')
parser.add_argument('--x', '-x', type=str, default='x',
help='column name of x axis')
parser.add_argument('--y', '-y', type=str, default='y',
help='column name of y axis')
parser.add_argument('--z', '-z', type=str, default='steer_angle',
help='column name of z (color) axis, displayed in greyscale and absolute value')
args = parser.parse_args()
#
# Parse the input CSV
#
with open(args.filename, newline='') as csvfile:
reader = csv.reader(csvfile)
names = next(reader)
x_ind = names.index(args.x)
y_ind = names.index(args.y)
z_ind = names.index(args.z)
xs: List[float] = []
ys: List[float] = []
zs: List[float] = []
try:
for i in range(args.skip_data_rows): # skip skipped rows
next(reader)
data_row_idx = 0
print(f"working: parsed {data_row_idx} rows", end='\r')
while True:
data_row = next(reader)
xs.append(float(data_row[x_ind]))
ys.append(float(data_row[y_ind]))
zs.append(float(data_row[z_ind]))
data_row_idx += 1
if data_row_idx % 1000 == 0:
print(f"working: parsed {data_row_idx} rows", end='\r')
except StopIteration:
print(f"finished: parsed {data_row_idx} rows")
#
# Postprocess z-axis (color) to absolute value
#
zs = [abs(z) for z in zs]
#
# Render graphs
#
print(f"working: rendering", end='\r')
sc = plt.scatter(xs, ys, c=zs, s=1)
plt.colorbar(sc)
print(f"finished: rendered ")
plt.subplots_adjust(bottom=0.001, left=0.001, top=0.999, right=0.999) # remove extraneous whitespace around plot
plt.show()