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()
59 key = tuple(w.keys())[0]
60 ax.set_title("Final path cost, Out-of-Slot Planner, scenario 5-1".format(key))
61 ax.set_xlabel("Elapsed time [s]")
62 ax.set_ylabel("Cost [m]")
64 err_hist = [0 for i in range(19)]
65 val_list = [[] for i in range(19)]
69 for i in range(len(w[key])):
78 print("min: {}, max: {}".format(mi, ma))
80 maxes = [max(val_list[i]) for i in range(19)]
81 mins = [min(val_list[i]) for i in range(19)]
82 average = [np.average(val_list[i]) for i in range(19)]
83 # 95 and 5 are not used
84 perct_95 = [np.percentile(val_list[i], [95])[0] for i in range(19)]
85 perct_5 = [np.percentile(val_list[i], [5])[0] for i in range(19)]
87 perct_10 = [np.percentile(val_list[i], [10])[0] for i in range(19)]
88 perct_20 = [np.percentile(val_list[i], [20])[0] for i in range(19)]
89 perct_30 = [np.percentile(val_list[i], [30])[0] for i in range(19)]
90 perct_40 = [np.percentile(val_list[i], [40])[0] for i in range(19)]
91 perct_50 = [np.percentile(val_list[i], [50])[0] for i in range(19)]
92 perct_60 = [np.percentile(val_list[i], [60])[0] for i in range(19)]
93 perct_70 = [np.percentile(val_list[i], [70])[0] for i in range(19)]
94 perct_80 = [np.percentile(val_list[i], [80])[0] for i in range(19)]
95 perct_90 = [np.percentile(val_list[i], [90])[0] for i in range(19)]
97 # find index of the closest to average path
100 for i in range(len(w[key]))
102 average_i = sorted(average_i, key=lambda i: i[1])
103 # this is for figures to the paper
104 print("min: {}".format(average_i[0]))
105 print("max: {}".format(average_i[-1]))
106 print("diff: {}".format(abs(average_i[0][1] - average_i[-1][1])))
115 label="Minimum and maximum, optimized",
123 label="10 % and 90 % percentile, optimized",
131 label="20 % and 80 % percentile, optimized",
139 label="30 % and 70 % percentile, optimized",
147 label="40 % and 60 % percentile, optimized",
149 # plot median and average
155 label="50 % percentile (median), optimized",
162 label="Average cost after optimization",
164 # plot average before path optimization
167 [np.average([i for i in no_opt[key].values()]) for i in range(1, 20)],
168 label="Average cost before optimization",
173 plt.xticks(range(1, 20), ["{:.2f}".format(0.1 * (k+1)) for k in range(m)])
176 plt.rcParams["font.size"] = 21
177 plt.rcParams['hatch.linewidth'] = 1.0
178 plt.rcParams['lines.linewidth'] = 1.0
180 plt.xticks(rotation=45)
181 plt.savefig("out.pdf", bbox_inches="tight")
184 def barplot(wl=[], t="", yl=None, lx="Entry Point Planner variant [-]", ly=""):
185 """Plot barplot graph.
188 wl -- What to plot list.
190 yl -- Y axis limit [min, max].
196 f, ax = plt.subplots()
203 [v for k, v in w.items()],
204 tick_label=[k for k, v in w.items()],
205 width=1 / (len(wl) + 1),
207 for i in range(1, len(wl) - 1):
210 [j + i * 1/len(wl) for j in range(len(w))],
211 [v for k, v in w.items()],
212 width=1 / (len(wl) + 1),
231 plt.xticks(rotation=45)
232 plt.savefig("out.eps", bbox_inches="tight")
235 def histplot(w={}, t="", lx="Algorithm computation time [s]", ly="Number of paths found [-]"):
236 """Plot histogram graph.
242 f, ax = plt.subplots()
243 ax.set_title("{} (log yscale)".format(t))
245 ax.set_xlim(-10, 500)
249 COLORS = ["tab:orange", "tab:red", "tab:blue", "tab:green"]
252 for ck, cv in w.items():
254 [v for k, v in w.items() if k == ck],
260 X_WHERE = np.percentile([v for k, v in w.items() if k == ck], [95])
261 print("percentile is {}".format(X_WHERE))
262 plt.axvline(X_WHERE, lw=1, linestyle="--", color=COLORS[i])
280 plt.legend([k for k, v in w.items()])
281 plt.xticks(rotation=45)
282 plt.savefig("out.eps", bbox_inches="tight")
285 if __name__ == "__main__":
286 if len(sys.argv) > 1:
290 if len(sys.argv) > 2:
291 scenario.DNAME = sys.argv[2]
293 plt.rcParams["font.size"] = 22
294 plt.rcParams["font.family"] = "sans-serif"
295 plt.rcParams["figure.figsize"] = [12, 12]
298 boxplot(scenario.time(), "Elapsed time", yl=[0.0004, 200], ly="Time [s]")
300 histplot(scenario.time(), "Histogram of time to find a path")
302 boxplot(scenario.cost(), "Final path cost", yl=[0, 80], ly="Cost [m]")
304 boxplots(scenario.costs())
306 histplot(scenario.cost(), "Final path cost histogram")
307 elif w == "orig_cost":
308 boxplot(scenario.orig_cost(), "Original path cost", yl=[0, 80], ly="Cost [m]")
309 elif w == "orig_hcost":
310 histplot(scenario.orig_cost(), "Original path cost histogram")
312 boxplot(scenario.cusp(), "Changes in direction", ly="Changes [-]")
314 histplot(scenario.cusp(), "Changes in direction histogram")
317 scenario.error_rate(),
318 "Path not found rate",
319 ly="Path not found [%]",
324 "Number of iterations",
329 print("""The following arguments are allowed:
331 time, htime, cost, hcost, cusp, hcusp, error, iter