1 """Procedures for plotting graphs."""
3 import matplotlib.pyplot as plt
8 def boxplot(w={}, t="", yl=None, lx="Elapsed time [s]", ly=""):
14 yl -- Y axis limit [min, max].
16 f, ax = plt.subplots()
18 if False: # is the y axis log scale?
19 ax.set_title("{} -- {} (log yscale)".format(scenario.SNAME, t))
22 ax.set_title("{} -- {}".format(scenario.SNAME, t))
27 ax.boxplot([v for k, v in w.items()], labels=[k for k, v in w.items()])
45 plt.xticks(rotation=45)
46 plt.savefig("out.eps", bbox_inches="tight")
50 """Plot boxplot for multiple times.
53 w -- What to plot. It is extracted from `w2`.
55 f, ax = plt.subplots()
58 [w, no_opt, iterations] = w2
60 key = tuple(w.keys())[0]
61 title = scenario.TITLE.split("/")[-2].split(".json")[0].split("sc")[1].replace("_", "-")
62 ax.set_title("Final path cost, out-of-slot planner, {}, ({} avg. iters.)".format(
64 np.average([i for i in iterations[key].values()]),
66 ax.set_xlabel("Elapsed time [s]")
67 ax.set_ylabel("Cost [m]")
68 eax.set_ylabel("Timed-out rate [%]")
71 err_hist = [0 for i in range(M)]
72 val_list = [[] for i in range(M)]
76 for i in range(len(w[key])):
85 for i in range(len(err_hist)):
86 err_hist[i] *= 100 / N
88 maxes = [max(val_list[i]) if len(val_list[i]) > 0 else 0 for i in range(M)]
90 mins = [min(val_list[i]) if len(val_list[i]) > 0 else 0 for i in range(M)]
92 ax.set_ylim([MIN -5, MAX +5])
96 #eax.set_ylim([-EMAX -5, 0])
98 average = [np.average(val_list[i]) for i in range(M)]
99 # 95 and 5 are not used
100 perct_95 = [np.percentile(val_list[i], [95])[0] if len(val_list[i]) > 0 else 0 for i in range(M)]
101 perct_5 = [np.percentile(val_list[i], [5])[0] if len(val_list[i]) > 0 else 0 for i in range(M)]
102 # percentiles by 10 %
103 perct_10 = [np.percentile(val_list[i], [10])[0] if len(val_list[i]) > 0 else 0 for i in range(M)]
104 perct_20 = [np.percentile(val_list[i], [20])[0] if len(val_list[i]) > 0 else 0 for i in range(M)]
105 perct_30 = [np.percentile(val_list[i], [30])[0] if len(val_list[i]) > 0 else 0 for i in range(M)]
106 perct_40 = [np.percentile(val_list[i], [40])[0] if len(val_list[i]) > 0 else 0 for i in range(M)]
107 perct_50 = [np.percentile(val_list[i], [50])[0] if len(val_list[i]) > 0 else 0 for i in range(M)]
108 perct_60 = [np.percentile(val_list[i], [60])[0] if len(val_list[i]) > 0 else 0 for i in range(M)]
109 perct_70 = [np.percentile(val_list[i], [70])[0] if len(val_list[i]) > 0 else 0 for i in range(M)]
110 perct_80 = [np.percentile(val_list[i], [80])[0] if len(val_list[i]) > 0 else 0 for i in range(M)]
111 perct_90 = [np.percentile(val_list[i], [90])[0] if len(val_list[i]) > 0 else 0 for i in range(M)]
113 # find index of the closest to average path
116 for i in range(len(w[key]))
118 average_i = sorted(average_i, key=lambda i: i[1])
119 # this is for figures to the paper -- min/max path cost
125 print("{} {}".format(n0i, average_i[-1][0]))
132 [i for i in err_hist],
133 [0 for i in range(1, M+1)],
136 label="Not found paths",
147 label="Minimum and maximum, optimized",
157 label="10 % and 90 % percentile, optimized",
167 label="20 % and 80 % percentile, optimized",
177 label="30 % and 70 % percentile, optimized",
187 label="40 % and 60 % percentile, optimized",
190 # plot median and average
197 label="50 % percentile (median), optimized",
206 label="Average cost after optimization",
209 # plot average before path optimization
212 # [np.average([i for i in no_opt[key].values()]) for i in range(1, M+1)],
213 # label="Average cost before optimization",
218 plt.xticks(range(1, M+1), ["{:.2f}".format(0.1 * (k+1)) for k in range(M)])
221 ax.tick_params(axis='x', labelrotation=45)
222 ax.legend(loc="upper left")
223 eax.legend(loc="upper right")
224 plt.savefig("out.pdf", bbox_inches="tight")
227 def barplot(wl=[], t="", yl=None, lx="Entry Point Planner variant [-]", ly=""):
228 """Plot barplot graph.
231 wl -- What to plot list.
233 yl -- Y axis limit [min, max].
239 f, ax = plt.subplots()
246 [v for k, v in w.items()],
247 tick_label=[k for k, v in w.items()],
248 width=1 / (len(wl) + 1),
250 for i in range(1, len(wl) - 1):
253 [j + i * 1/len(wl) for j in range(len(w))],
254 [v for k, v in w.items()],
255 width=1 / (len(wl) + 1),
274 plt.xticks(rotation=45)
275 plt.savefig("out.eps", bbox_inches="tight")
278 def histplot(w={}, t="", lx="Algorithm computation time [s]", ly="Number of paths found [-]"):
279 """Plot histogram graph.
285 f, ax = plt.subplots()
286 ax.set_title("{} (log yscale)".format(t))
288 ax.set_xlim(-10, 500)
292 COLORS = ["tab:orange", "tab:red", "tab:blue", "tab:green"]
295 for ck, cv in w.items():
297 [v for k, v in w.items() if k == ck],
303 X_WHERE = np.percentile([v for k, v in w.items() if k == ck], [95])
304 print("percentile is {}".format(X_WHERE))
305 plt.axvline(X_WHERE, lw=1, linestyle="--", color=COLORS[i])
323 plt.legend([k for k, v in w.items()])
324 plt.xticks(rotation=45)
325 plt.savefig("out.eps", bbox_inches="tight")
328 if __name__ == "__main__":
329 if len(sys.argv) > 1:
333 if len(sys.argv) > 2:
334 scenario.DNAME = sys.argv[2]
336 plt.rcParams["figure.figsize"] = [12, 12]
337 plt.rcParams["font.size"] = 21
338 plt.rcParams["font.family"] = "cmr10"
339 plt.rcParams["hatch.linewidth"] = 1.0
340 plt.rcParams["lines.linewidth"] = 1.0
343 boxplot(scenario.time(), "Elapsed time", yl=[0.0004, 200], ly="Time [s]")
345 histplot(scenario.time(), "Histogram of time to find a path")
347 boxplot(scenario.cost(), "Final path cost", yl=[0, 80], ly="Cost [m]")
349 boxplots(scenario.costs())
351 histplot(scenario.cost(), "Final path cost histogram")
352 elif w == "orig_cost":
353 boxplot(scenario.orig_cost(), "Original path cost", yl=[0, 80], ly="Cost [m]")
354 elif w == "orig_hcost":
355 histplot(scenario.orig_cost(), "Original path cost histogram")
357 boxplot(scenario.cusp(), "Changes in direction", ly="Changes [-]")
359 histplot(scenario.cusp(), "Changes in direction histogram")
362 scenario.error_rate(),
363 "Path not found rate",
364 ly="Path not found [%]",
369 "Number of iterations",
374 print("""The following arguments are allowed:
376 time, htime, cost, hcost, cusp, hcusp, error, iter