1 """Procedures for plotting graphs."""
3 import matplotlib.pyplot as plt
8 def boxplot(w={}, t="", yl=None, lx="Scenario [-]", ly=""):
14 yl -- Y axis limit [min, max].
16 f, ax = plt.subplots()
18 ax.set_title("{} (log yscale)".format(t))
23 ax.boxplot([v for k, v in w.items()], labels=[k for k, v in w.items()])
41 plt.savefig("out.eps", bbox_inches="tight")
44 def barplot(wl=[], t="", yl=None, lx="Scenario [-]", ly=""):
45 """Plot barplot graph.
48 wl -- What to plot list.
50 yl -- Y axis limit [min, max].
56 f, ax = plt.subplots()
63 [v for k, v in w.items()],
64 tick_label=[k for k, v in w.items()],
65 width=1 / (len(wl) + 1),
67 for i in range(1, len(wl) - 1):
70 [j + i * 1/len(wl) for j in range(len(w))],
71 [v for k, v in w.items()],
72 width=1 / (len(wl) + 1),
91 plt.savefig("out.eps", bbox_inches="tight")
94 def histplot(w={}, t=""):
95 """Plot histogram graph.
101 f, ax = plt.subplots()
102 ax.set_title("{} (log yscale)".format(t))
104 ax.set_xlim(-10, 500)
108 COLORS = ["tab:orange", "tab:red", "tab:blue", "tab:green"]
111 for ck, cv in w.items():
113 [v for k, v in w.items() if k == ck],
119 X_WHERE = np.percentile([v for k, v in w.items() if k == ck], [95])
120 print("percentile is {}".format(X_WHERE))
121 plt.axvline(X_WHERE, lw=1, linestyle="--", color=COLORS[i])
139 plt.legend([k for k, v in w.items()])
140 plt.savefig("out.eps", bbox_inches="tight")
143 if __name__ == "__main__":
144 if len(sys.argv) > 1:
148 if len(sys.argv) > 2:
149 scenario.DNAME = sys.argv[2]
151 plt.rcParams["font.size"] = 22
152 plt.rcParams["font.family"] = "sans-serif"
153 plt.rcParams["figure.figsize"] = [12, 4]
156 boxplot(scenario.time(), "Elapsed time", yl=[0.05, 200], ly="Time [s]")
158 histplot(scenario.time(), "Elapsed time histogram")
160 boxplot(scenario.cost(), "Final path cost", yl=[10, 400], ly="Cost [m]")
162 histplot(scenario.cost(), "Final path cost histogram")
163 elif w == "orig_cost":
164 boxplot(scenario.orig_cost(), "Original path cost", yl=[10, 400], ly="Cost [m]")
165 elif w == "orig_hcost":
166 histplot(scenario.orig_cost(), "Original path cost histogram")
168 boxplot(scenario.cusp(), "Changes in direction", ly="Changes [-]")
170 histplot(scenario.cusp(), "Changes in direction histogram")
173 scenario.error_rate(),
174 "Path not found rate",
175 ly="Path not found [%]",
180 "Number of iterations",
185 print("""The following arguments are allowed:
187 time, htime, cost, hcost, cusp, hcusp, error, iter