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.pdf", 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]
70 title = "scenario {}".format(title)
71 title = "Final path cost, {}, ({} avg. iters.)".format(
73 np.average([i for i in iterations[key].values()]),
78 ax.set_xlabel("Number of iterations [-]")
79 ax.set_ylabel("Cost [m]")
80 eax.set_ylabel("Finished with no path [%]")
83 err_hist = [0 for i in range(M)]
84 val_list = [[] for i in range(M)]
88 for i in range(len(w[key])):
97 for i in range(len(err_hist)):
98 err_hist[i] *= 100 / N
100 maxes = [max(val_list[i]) if len(val_list[i]) > 0 else 0 for i in range(M)]
102 mins = [min(val_list[i]) if len(val_list[i]) > 0 else 0 for i in range(M)]
107 ax.set_ylim([0, 100])
108 eax.set_ylim([0, 100])
110 average = [np.average(val_list[i]) for i in range(M)]
111 # 95 and 5 are not used
112 perct_95 = [np.percentile(val_list[i], [95])[0] if len(val_list[i]) > 0 else 0 for i in range(M)]
113 perct_5 = [np.percentile(val_list[i], [5])[0] if len(val_list[i]) > 0 else 0 for i in range(M)]
114 # percentiles by 10 %
115 perct_10 = [np.percentile(val_list[i], [10])[0] if len(val_list[i]) > 0 else 0 for i in range(M)]
116 perct_20 = [np.percentile(val_list[i], [20])[0] if len(val_list[i]) > 0 else 0 for i in range(M)]
117 perct_30 = [np.percentile(val_list[i], [30])[0] if len(val_list[i]) > 0 else 0 for i in range(M)]
118 perct_40 = [np.percentile(val_list[i], [40])[0] if len(val_list[i]) > 0 else 0 for i in range(M)]
119 perct_50 = [np.percentile(val_list[i], [50])[0] if len(val_list[i]) > 0 else 0 for i in range(M)]
120 perct_60 = [np.percentile(val_list[i], [60])[0] if len(val_list[i]) > 0 else 0 for i in range(M)]
121 perct_70 = [np.percentile(val_list[i], [70])[0] if len(val_list[i]) > 0 else 0 for i in range(M)]
122 perct_80 = [np.percentile(val_list[i], [80])[0] if len(val_list[i]) > 0 else 0 for i in range(M)]
123 perct_90 = [np.percentile(val_list[i], [90])[0] if len(val_list[i]) > 0 else 0 for i in range(M)]
125 # find index of the closest to average path
128 for i in range(len(w[key]))
130 average_i = sorted(average_i, key=lambda i: i[1])
131 # this is for figures to the paper -- min/max path cost
137 print("{} {}".format(n0i, average_i[-1][0]))
144 [i for i in err_hist],
145 [0 for i in range(1, M+1)],
148 label="No path found",
159 label="Minimum and maximum",
169 label="10 % and 90 % percentile",
179 label="20 % and 80 % percentile",
189 label="30 % and 70 % percentile",
199 label="40 % and 60 % percentile",
202 # plot median and average
209 label="50 % percentile (median)",
218 label="Average cost",
221 # plot average before path optimization
224 # [np.average([i for i in no_opt[key].values()]) for i in range(1, M+1)],
225 # label="Average cost before optimization",
232 ax.tick_params(axis='x', labelrotation=45)
233 ax.legend(loc="upper left")
234 eax.legend(loc="upper right")
235 plt.savefig("out.pdf", bbox_inches="tight")
238 def barplot(wl=[], t="", yl=None, lx="Entry Point Planner variant [-]", ly=""):
239 """Plot barplot graph.
242 wl -- What to plot list.
244 yl -- Y axis limit [min, max].
250 f, ax = plt.subplots()
257 [v for k, v in w.items()],
258 tick_label=[k for k, v in w.items()],
259 width=1 / (len(wl) + 1),
261 for i in range(1, len(wl) - 1):
264 [j + i * 1/len(wl) for j in range(len(w))],
265 [v for k, v in w.items()],
266 width=1 / (len(wl) + 1),
285 plt.xticks(rotation=45)
286 plt.savefig("out.pdf", bbox_inches="tight")
289 def histplot(w={}, t="", lx="Algorithm computation time [s]", ly="Number of paths found [-]"):
290 """Plot histogram graph.
296 f, ax = plt.subplots()
297 ax.set_title("{} (log yscale)".format(t))
299 ax.set_xlim(-10, 500)
303 COLORS = ["tab:orange", "tab:red", "tab:blue", "tab:green"]
306 for ck, cv in w.items():
308 [v for k, v in w.items() if k == ck],
314 X_WHERE = np.percentile([v for k, v in w.items() if k == ck], [95])
315 print("percentile is {}".format(X_WHERE))
316 plt.axvline(X_WHERE, lw=1, linestyle="--", color=COLORS[i])
334 plt.legend([k for k, v in w.items()])
335 plt.xticks(rotation=45)
336 plt.savefig("out.pdf", bbox_inches="tight")
339 if __name__ == "__main__":
340 if len(sys.argv) > 1:
344 if len(sys.argv) > 2:
345 scenario.DNAME = sys.argv[2]
347 plt.rcParams["figure.figsize"] = [12, 12]
348 plt.rcParams["font.size"] = 24
349 plt.rcParams["font.family"] = "cmr10"
350 plt.rcParams["hatch.linewidth"] = 1.0
351 plt.rcParams["lines.linewidth"] = 1.0
352 plt.rc('axes', unicode_minus=False)
355 boxplot(scenario.time(), "Elapsed time", yl=[0.0004, 200], ly="Time [s]")
357 histplot(scenario.time(), "Histogram of time to find a path")
359 boxplot(scenario.cost(), "Final path cost", yl=[0, 80], ly="Cost [m]")
361 boxplots(scenario.costs())
363 histplot(scenario.cost(), "Final path cost histogram")
364 elif w == "orig_cost":
365 boxplot(scenario.orig_cost(), "Original path cost", yl=[0, 80], ly="Cost [m]")
366 elif w == "orig_hcost":
367 histplot(scenario.orig_cost(), "Original path cost histogram")
369 boxplot(scenario.cusp(), "Changes in direction", ly="Changes [-]")
371 histplot(scenario.cusp(), "Changes in direction histogram")
374 scenario.error_rate(),
375 "Path not found rate",
376 ly="Path not found [%]",
381 "Number of iterations",
386 print("""The following arguments are allowed:
388 time, htime, cost, hcost, cusp, hcusp, error, iter