-
Notifications
You must be signed in to change notification settings - Fork 4
/
plot_csv.py
68 lines (53 loc) · 1.72 KB
/
plot_csv.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
68
# 11/05/2022
# IN-LP
#
import numpy as np
import matplotlib.pyplot as plt
import signal
import os
signal.signal(signal.SIGINT, signal.SIG_DFL)
_, _, files = next(os.walk("./_csv_file"))
NN = len(files)
xx_csv = {}
Tlist = []
for ii in range(NN):
xx_csv[ii] = np.genfromtxt("_csv_file/agent_{}.csv".format(ii), delimiter=',').T
Tlist.append(xx_csv[ii].shape[1])
n_x = xx_csv[ii].shape[0]
print(n_x)
Tmax = min(Tlist)
xx = np.zeros((NN*n_x,Tmax))
for ii in range(NN):
for jj in range(n_x):
index_ii = ii*n_x+jj
xx[index_ii,:] = xx_csv[ii][jj][:Tmax] # useful to remove last samples
plt.figure()
for x in xx:
plt.plot(range(Tmax), x)
block_var = False if n_x < 3 else True
plt.show(block=block_var)
if 1 and n_x == 2: # animation
plt.figure()
dt = 4 # sub-sampling of the plot horizon
#dt = 3
for tt in range(0,Tmax,dt):
xx_tt = xx[:,tt].T
for ii in range(NN):
index_ii = ii*n_x + np.arange(n_x)
xx_ii = xx_tt[index_ii]
plt.plot(xx_ii[0],xx_ii[1], marker='o', markersize=15, fillstyle='none', color = 'tab:red')
axes_lim = (np.min(xx)-1,np.max(xx)+1)
#axes_lim = (-5,5)
plt.xlim(axes_lim); plt.ylim(axes_lim)
plt.plot(xx[0:n_x*NN:n_x,:].T,xx[1:n_x*NN:n_x,:].T, alpha=0.3) # uncomment to show trajectories
plt.axis('equal')
plt.text(0,3,"iter: {}".format(tt)) # write the iteration
plt.text(0,2.5,"time: {}s".format(tt*5e-2)) # write the time (iteration*sampling time defined in the launch file)
plt.grid()
#plt.show(block=True)
plt.show(block=False)
#plt.pause(0.1)
plt.pause(0.0001)
if tt < Tmax - dt - 1:
plt.clf()
plt.show()