-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplotter.py
More file actions
150 lines (115 loc) · 4.02 KB
/
plotter.py
File metadata and controls
150 lines (115 loc) · 4.02 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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
from matplotlib import pyplot as plt
import pickle as pk
import numpy as np
import misc
from matplotlib.lines import Line2D
#
from matplotlib import rc
rc('font',**{'family':'sans-serif','sans-serif':['Helvetica']})
## for Palatino and other serif fonts use:
#rc('font',**{'family':'Serif','Serif':['Palatino']})
rc('text', usetex=True)
legend_titles = {
"max_force": "Max Force",
"phys_time": "Timestep Physics",
"num": "\# of Boids",
"rule_time": "Timestep Rules"
}
y_labels = {
0: "$\sigma_{\hat{x}}$",
1: "$\sigma_{\hat{v}}$",
2: "$\mu_{\hat{x}}$"
}
def import_data(files):
data = []
for file in files:
ds = pk.load(open(misc.wd() + file + "_data.pickle", 'rb'))
for d in ds:
data.append(d)
return data
def plot_mean(data):
x = np.mean(np.array(data), axis=0)
plt.plot(x)
plt.xlabel("Timestep")
plt.ylabel("Mean")
plt.show()
def plot_multi(vars, data):
ls = [None] * len(data)
fig, ax = plt.subplots()
for i in range(len(data)):
d = np.array(data[i])
d = d[:, vars["y"]]
y = np.mean(d, axis=0) * vars["S2r"] # Converting back to meters
x, y, T0 = ND(vars, y, i)
st = str(vars["variables"][i])
ls[i], = ax.plot(x, y, label = st)
ax.set_xlabel("$\hat{t}$", fontsize=20)
ax.set_ylabel(y_labels[vars["y"]], fontsize=20)
plt.grid()
if len(vars["variables"]) > 4:
leg = ax.legend(title=legend_titles[vars["working_var"]], ncol=2)
else:
leg = ax.legend(title=legend_titles[vars["working_var"]], ncol=1)
plt.xlim(0, vars["run_time"]/T0)
plt.ylim(bottom=0)
plt.tight_layout()
plt.show()
def ND(vars, y, i):
# The several cases for ND will be handled individually here
T0 = vars["s"] / vars["max_speed"] # Time to do a full lap
if vars["y"] == 0: # x_std
R0 = vars["s"] / vars["num"] # Mean space between separated boids
elif vars["y"] == 1: # v_std
R0 = vars["max_speed"]
elif vars["y"] == 2: #
R0 = vars["s"]
y = y / R0
# Special handling for changing physics time
if vars["working_var"] == 'phys_time':
x = np.linspace(0, vars["run_time"], int(vars["run_time"] / vars["variables"][i])) / T0
elif vars["working_var"] == 'max_speed':
T0 = (vars["boid_size"] / vars["variables"][i])
x = np.linspace(0, vars["run_time"],
int(vars["run_time"] / vars["variables"][i])) / T0
else:
x = np.linspace(0, vars["run_time"], int(vars["run_time"] / vars["phys_time"])) / T0
return x, y, T0
def plot_multi_mean_time(vars, data):
ls = [None] * len(data)
fig, ax = plt.subplots()
for i in range(len(data)):
d = data[i][0] # The 0 index is for STD in x
y = np.mean(np.array(d), axis=0)
x = np.linspace(0, vars["run_time"], len(y))
st = str(vars["variables"][i])
ls[i], = ax.plot(x, y, label = st)
ax.set_xlabel("$t \; [s]$", fontsize=16)
ax.set_ylabel("$\sigma_x \; [m]$", fontsize=16)
plt.grid()
if len(vars["variables"]) > 4:
leg = ax.legend(title='Timestep', ncol=2)
else:
leg = ax.legend(title='Timestep', ncol=1)
plt.xlim(0,int(vars["run_time"]))
plt.tight_layout()
plt.show()
def plot_multi_velocity(vars, data):
ls = [None] * len(data)
fig, ax = plt.subplots()
data = np.array(data)
for i in range(data.shape[0]):
d = data[i,:,1]
y = np.mean(np.array(d), axis=0)
x = np.linspace(0, vars["run_time"], len(y))
st = str(vars["variables"][i])
ls[i], = ax.plot(x, y, label=st)
ax.set_xlabel("$t \; [s]$", fontsize=16)
ax.set_ylabel("$\sigma_x \; [m]$", fontsize=16)
plt.grid()
if len(vars["variables"]) > 4:
leg = ax.legend(title="Variable", ncol=2, fontsize=12)
else:
leg = ax.legend(title="Variable", ncol=1, fontsize=12)
plt.xlim(0, int(vars["run_time"]))
plt.tight_layout()
plt.show()