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))
105 for ck, cv in w.items():
107 [v for k, v in w.items() if k == ck],
112 X_WHERE = np.percentile([v for k, v in w.items() if k == ck], [95])
113 plt.axvline(X_WHERE, lw=1, linestyle="--")
130 plt.legend([k for k, v in w.items()])
131 plt.savefig("out.eps", bbox_inches="tight")
134 if __name__ == "__main__":
135 if len(sys.argv) > 1:
140 plt.rcParams["font.size"] = 22
141 plt.rcParams["font.family"] = "sans-serif"
142 plt.rcParams["figure.figsize"] = [12, 4]
145 boxplot(scenario.time(), "Elapsed time", yl=[0.05, 200], ly="Time [s]")
147 histplot(scenario.time(), "Elapsed time histogram")
149 boxplot(scenario.cost(), "Final path cost", yl=[10, 400], ly="Cost [m]")
151 histplot(scenario.cost(), "Final path cost histogram")
152 elif w == "orig_cost":
153 boxplot(scenario.orig_cost(), "Original path cost", yl=[10, 400], ly="Cost [m]")
154 elif w == "orig_hcost":
155 histplot(scenario.orig_cost(), "Original path cost histogram")
157 boxplot(scenario.cusp(), "Changes in direction", ly="Changes [-]")
159 histplot(scenario.cusp(), "Changes in direction histogram")
161 barplot(scenario.error_rate(), "Error rate", ly="Error [%]")
165 "Number of iterations",
170 print("""The following arguments are allowed:
172 time, htime, cost, hcost, cusp, hcusp, error, iter