-
Notifications
You must be signed in to change notification settings - Fork 6
/
plot_helpers.py
238 lines (226 loc) · 8.24 KB
/
plot_helpers.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
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
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
import numpy as np
import matplotlib as mpl
import matplotlib.pyplot as plt
mpl.rcParams.update({'font.size': 16})
from csv_dictionary import *
boxes = makeCsvDictOfArrays('test_results/BENCHMARK_boxes_dt.csv')
color1 = [0, 0, 0.5]
color2 = [0.5, 0.5, 0.5]
linestyle1 = '-'
linestyle2 = '--'
def plotTimePosition3(time, position3):
plt.gcf()
plt.plot(time, position3[:,0], linewidth=4.0, linestyle=linestyle1, color=color1)
plt.plot(time, position3[:,1], linewidth=4.0, linestyle=linestyle2, color=color1)
plt.plot(time, position3[:,2], linewidth=2.0, linestyle=linestyle1, color=color2)
plt.xlabel('Time (s)')
plt.ylabel('Position (m)')
plt.grid()
plt.legend(['x','y','z'], loc='best');
# helper function for resizing axes
def vector_scale(x, scale):
mean = np.mean(x)
centered = x - mean
return mean + centered*scale
def vector_log10_scale(x, scale):
logx = np.log10(x)
scaled = vector_scale(logx, scale)
return [10**l for l in scaled]
# Create a plot with time step Dt on horizontal axis
# Value of `yname` plotted on vertical axis
def plotEnginesDt(params, yname
, axscale=1.1
, ayscale=1.1
, csvDict=boxes
, legend='best'
, xname='dt'
, xlabel='Time step (s)'
, ylabel='Error'
, xlim=[]
, ylim=[]
, xscale='linear'
, yscale='linear'
, title='title'
, skipDart=False
):
engines = {}
engines['bullet'] = ['$B$', 'b--']
if not skipDart:
engines['dart'] = ['$d$', 'g--']
engines['ode'] = ['$O$', 'r--']
engines['simbody'] = ['$S$', 'k--']
fig = plt.figure()
xdata = {}
ydata = {}
for e in sorted(engines.keys()):
params['engine'] = e
ii = np.array(list(query(csvDict, params)))
xdata[e] = csvDict[xname][ii]
ydata[e] = csvDict[yname][ii]
color = engines[e][1][0]
plt.plot(xdata[e]
, ydata[e]+np.finfo(float).eps
, engines[e][1]
, mfc=color
, marker=engines[e][0]
, markersize=20.0
, markeredgecolor=color
, linewidth=2.0
)
plt.grid()
plt.xlabel(xlabel, fontsize=18)
plt.ylabel(ylabel, fontsize=18)
plt.gca().set_xscale(xscale)
plt.gca().set_yscale(yscale)
plt.title(title)
plt.gcf().set_size_inches(10, 6)
if len(xlim) == 2:
plt.xlim(xlim)
elif xscale == 'log':
plt.xlim(vector_log10_scale(plt.xlim(), axscale))
else:
plt.xlim(vector_scale(plt.xlim(), axscale))
if len(ylim) == 2:
plt.ylim(ylim)
elif yscale == 'log':
plt.ylim(vector_log10_scale(plt.ylim(), ayscale))
else:
plt.ylim(vector_scale(plt.ylim(), ayscale))
plt.legend(sorted(engines.keys()), loc=legend)
plt.show();
# some extra info about each plot
xdata_minmax = {}
ydata_minmax = {}
for e in sorted(engines.keys()):
xdata_minmax[e] = [min(xdata[e]), max(xdata[e])]
ydata_minmax[e] = [min(ydata[e]), max(ydata[e])]
def plotEnginesTime(params, yname
, csvDict=boxes
, legend='best'
, skipDart=False
, xname='timeRatio'
, xlabel='Time ratio (real / sim)'
, ylabel='Error'
, xlim=[]
, ylim=[]
, xscale='linear'
, yscale='linear'
, title='title'
):
plotEnginesDt(params, yname
, csvDict=csvDict
, legend=legend
, skipDart=skipDart
, xname=xname
, xlabel=xlabel
, ylabel=ylabel
, xlim=xlim
, ylim=ylim
, xscale=xscale
, yscale=yscale
, title=title
)
def plotEnginesModelCount(params, yname
, csvDict=boxes
, legend='best'
, skipDart=False
, xname='modelCount'
, xlabel='Model count'
, ylabel='Time ratio (real / sim)'
, xlim=[]
, ylim=[]
, xscale='linear'
, yscale='linear'
, title='title'
):
plotEnginesDt(params, yname
, csvDict=csvDict
, legend=legend
, skipDart=skipDart
, xname=xname
, xlabel=xlabel
, ylabel=ylabel
, xlim=xlim
, ylim=ylim
, xscale=xscale
, yscale=yscale
, title=title
)
def plot3TimeDt(params
, csvDict=boxes
, yname='linPositionErr_maxAbs'
, title=''
, skipDart=False
, xscale='linear'
, yscale='linear'
):
plotEnginesDt(params
, csvDict=csvDict
, yname=yname
, title=title
, skipDart=skipDart
, xscale=xscale
, yscale=yscale
)
plotEnginesDt(params
, csvDict=csvDict
, yname='timeRatio'
, ylabel='Computational time / sim time'
, title='Computational time'
, skipDart=skipDart
, xscale=xscale
, yscale=yscale
)
plotEnginesTime(params
, csvDict=csvDict
, yname=yname
, title=title
, skipDart=skipDart
, xscale=xscale
, yscale=yscale
)
def plotErrorDt(classname, title_prefix
, csvDict=boxes
, legend='best'
, xscale='linear'
, yscale='linear'):
p = {}
p['classname'] = classname
title_prefix = title_prefix
plotEnginesDt(p, yname='linPositionErr_maxAbs', title=title_prefix + 'position'
, csvDict=csvDict, legend=legend, xscale=xscale, yscale=yscale)
plotEnginesDt(p, yname='angPositionErr_mag_maxAbs', title=title_prefix + 'angle'
, csvDict=csvDict, legend=legend, yscale=yscale)
plotEnginesDt(p, yname='linVelocityErr_maxAbs', title=title_prefix + 'velocity'
, csvDict=csvDict, legend=legend, yscale=yscale)
plotEnginesDt(p, yname='angMomentumErr_maxAbs', title=title_prefix + 'angular momentum'
, csvDict=csvDict, legend=legend, yscale=yscale)
plotEnginesDt(p, yname='energyError_maxAbs', title=title_prefix + 'energy'
, csvDict=csvDict, legend=legend, yscale=yscale)
def plotTimeDt(classname, title_prefix
, csvDict=boxes
, legend='best'
, yscale='linear'):
p = {}
p['classname'] = classname
title_prefix = title_prefix
plotEnginesDt(p, yname='timeRatio', title=title_prefix + 'time ratio'
, ylabel='Time ratio (real / sim)'
, csvDict=csvDict, legend=legend, yscale=yscale)
def plotErrorTime(classname, title_prefix
, csvDict=boxes
, legend='best'
, yscale='linear'):
p = {}
p['classname'] = classname
title_prefix = title_prefix
plotEnginesTime(p, yname='linPositionErr_maxAbs', title=title_prefix + 'position'
, csvDict=csvDict, legend=legend, yscale=yscale)
plotEnginesTime(p, yname='angPositionErr_mag_maxAbs', title=title_prefix + 'angle'
, csvDict=csvDict, legend=legend, yscale=yscale)
plotEnginesTime(p, yname='linVelocityErr_maxAbs', title=title_prefix + 'velocity'
, csvDict=csvDict, legend=legend, yscale=yscale)
plotEnginesTime(p, yname='angMomentumErr_maxAbs', title=title_prefix + 'angular momentum'
, csvDict=csvDict, legend=legend, yscale=yscale)
plotEnginesTime(p, yname='energyError_maxAbs', title=title_prefix + 'energy'
, csvDict=csvDict, legend=legend, yscale=yscale)