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()
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, {}".format(title))
63 ax.set_xlabel("Elapsed time [s]")
64 ax.set_ylabel("Cost [m]")
65 eax.set_ylabel("Timed-out rate [%]")
68 err_hist = [0 for i in range(M)]
69 val_list = [[] for i in range(M)]
73 for i in range(len(w[key])):
82 for i in range(len(err_hist)):
83 err_hist[i] *= 100 / N
85 maxes = [max(val_list[i]) if len(val_list[i]) > 0 else 0 for i in range(M)]
87 mins = [min(val_list[i]) if len(val_list[i]) > 0 else 0 for i in range(M)]
89 ax.set_ylim([MIN -5, MAX +5])
93 #eax.set_ylim([-EMAX -5, 0])
95 average = [np.average(val_list[i]) for i in range(M)]
96 # 95 and 5 are not used
97 perct_95 = [np.percentile(val_list[i], [95])[0] if len(val_list[i]) > 0 else 0 for i in range(M)]
98 perct_5 = [np.percentile(val_list[i], [5])[0] if len(val_list[i]) > 0 else 0 for i in range(M)]
100 perct_10 = [np.percentile(val_list[i], [10])[0] if len(val_list[i]) > 0 else 0 for i in range(M)]
101 perct_20 = [np.percentile(val_list[i], [20])[0] if len(val_list[i]) > 0 else 0 for i in range(M)]
102 perct_30 = [np.percentile(val_list[i], [30])[0] if len(val_list[i]) > 0 else 0 for i in range(M)]
103 perct_40 = [np.percentile(val_list[i], [40])[0] if len(val_list[i]) > 0 else 0 for i in range(M)]
104 perct_50 = [np.percentile(val_list[i], [50])[0] if len(val_list[i]) > 0 else 0 for i in range(M)]
105 perct_60 = [np.percentile(val_list[i], [60])[0] if len(val_list[i]) > 0 else 0 for i in range(M)]
106 perct_70 = [np.percentile(val_list[i], [70])[0] if len(val_list[i]) > 0 else 0 for i in range(M)]
107 perct_80 = [np.percentile(val_list[i], [80])[0] if len(val_list[i]) > 0 else 0 for i in range(M)]
108 perct_90 = [np.percentile(val_list[i], [90])[0] if len(val_list[i]) > 0 else 0 for i in range(M)]
110 # find index of the closest to average path
113 for i in range(len(w[key]))
115 average_i = sorted(average_i, key=lambda i: i[1])
116 # this is for figures to the paper -- min/max path cost
122 print("{} {}".format(n0i, average_i[-1][0]))
129 [i for i in err_hist],
130 [0 for i in range(1, M+1)],
133 label="Not found paths",
144 label="Minimum and maximum, optimized",
154 label="10 % and 90 % percentile, optimized",
164 label="20 % and 80 % percentile, optimized",
174 label="30 % and 70 % percentile, optimized",
184 label="40 % and 60 % percentile, optimized",
187 # plot median and average
194 label="50 % percentile (median), optimized",
203 label="Average cost after optimization",
206 # plot average before path optimization
209 # [np.average([i for i in no_opt[key].values()]) for i in range(1, M+1)],
210 # label="Average cost before optimization",
215 plt.xticks(range(1, M+1), ["{:.2f}".format(0.1 * (k+1)) for k in range(M)])
218 ax.tick_params(axis='x', labelrotation=45)
219 ax.legend(loc="upper left")
220 eax.legend(loc="upper right")
221 plt.savefig("out.pdf", bbox_inches="tight")
224 def barplot(wl=[], t="", yl=None, lx="Entry Point Planner variant [-]", ly=""):
225 """Plot barplot graph.
228 wl -- What to plot list.
230 yl -- Y axis limit [min, max].
236 f, ax = plt.subplots()
243 [v for k, v in w.items()],
244 tick_label=[k for k, v in w.items()],
245 width=1 / (len(wl) + 1),
247 for i in range(1, len(wl) - 1):
250 [j + i * 1/len(wl) for j in range(len(w))],
251 [v for k, v in w.items()],
252 width=1 / (len(wl) + 1),
271 plt.xticks(rotation=45)
272 plt.savefig("out.eps", bbox_inches="tight")
275 def histplot(w={}, t="", lx="Algorithm computation time [s]", ly="Number of paths found [-]"):
276 """Plot histogram graph.
282 f, ax = plt.subplots()
283 ax.set_title("{} (log yscale)".format(t))
285 ax.set_xlim(-10, 500)
289 COLORS = ["tab:orange", "tab:red", "tab:blue", "tab:green"]
292 for ck, cv in w.items():
294 [v for k, v in w.items() if k == ck],
300 X_WHERE = np.percentile([v for k, v in w.items() if k == ck], [95])
301 print("percentile is {}".format(X_WHERE))
302 plt.axvline(X_WHERE, lw=1, linestyle="--", color=COLORS[i])
320 plt.legend([k for k, v in w.items()])
321 plt.xticks(rotation=45)
322 plt.savefig("out.eps", bbox_inches="tight")
325 if __name__ == "__main__":
326 if len(sys.argv) > 1:
330 if len(sys.argv) > 2:
331 scenario.DNAME = sys.argv[2]
333 plt.rcParams["figure.figsize"] = [12, 12]
334 plt.rcParams["font.size"] = 21
335 plt.rcParams["font.family"] = "cmr10"
336 plt.rcParams["hatch.linewidth"] = 1.0
337 plt.rcParams["lines.linewidth"] = 1.0
340 boxplot(scenario.time(), "Elapsed time", yl=[0.0004, 200], ly="Time [s]")
342 histplot(scenario.time(), "Histogram of time to find a path")
344 boxplot(scenario.cost(), "Final path cost", yl=[0, 80], ly="Cost [m]")
346 boxplots(scenario.costs())
348 histplot(scenario.cost(), "Final path cost histogram")
349 elif w == "orig_cost":
350 boxplot(scenario.orig_cost(), "Original path cost", yl=[0, 80], ly="Cost [m]")
351 elif w == "orig_hcost":
352 histplot(scenario.orig_cost(), "Original path cost histogram")
354 boxplot(scenario.cusp(), "Changes in direction", ly="Changes [-]")
356 histplot(scenario.cusp(), "Changes in direction histogram")
359 scenario.error_rate(),
360 "Path not found rate",
361 ly="Path not found [%]",
366 "Number of iterations",
371 print("""The following arguments are allowed:
373 time, htime, cost, hcost, cusp, hcusp, error, iter