1 # -*- coding: utf-8 -*-
2 """This module contain functions to ease graph plots."""
4 from matplotlib import pyplot as plt
6 from sys import argv, exit
8 def load_trajectory(fname):
9 """Load trajectory from file.
12 fname -- The file name.
15 raise ValueError("File name as argument needed")
16 with open(fname, "r") as f:
17 trajectory = loads(f.read())
20 def load_trajectories(dname):
21 """Load trajectories from directory.
24 dname -- The directory name.
27 raise ValueError("Directory name as argument needed")
29 for f in listdir(dname):
30 trajectories.append(load_trajectory("{}/{}".format(dname, f)))
35 plt.rcParams["font.size"] = 24
37 ax = fig.add_subplot(111)
38 #ax.set_aspect("equal")
40 #ax.set_title("TITLE")
41 #ax.set_xlabel("Time [s]")
42 #ax.set_ylabel("YLABEL")
46 #plt.plot(xcoords, ycoords, color="blue", label="LABEL")
47 #plt.hist(vals) # log=?, range=[?], bins=?
48 #ax.bar(xvals, yvals) # width=?
49 #ax.set_xticklabels(xvals, rotation=90)
52 #plt.savefig("WHATEVER")
54 def count_if_exist(trajectories, what):
55 """From multiple trajectories compute the number of occurences.
58 trajectories -- The list of trajectories.
59 what -- Number of occurences of what to compute.
62 for t in trajectories:
70 def get_lasts_if_exist(trajectories, what):
71 """From multiple trajectories get the list of last values.
74 trajectories -- The list of trajectories.
75 what -- The last values of what to take.
78 for t in trajectories:
80 val.append(t[what][-1])
85 def get_maxs_if_exist(trajectories, what):
86 """From multiple trajectories get the list of maximum values.
89 trajectories -- The list of trajectories.
90 what -- The maximum values of what to take.
93 for t in trajectories:
95 val.append(max(t[what]))
100 def plot_successrate():
101 """Plot success rate of single/multi-core implementations."""
102 LOGF="logs_T2st3co2_lpar"
103 LOGSF=["opt0", "opt1"]
105 "opt0": "T2, st3, co2, no opt",
106 "opt1": "T2, st3, co2, with opt"}
110 r["{}".format(LEG[sf])] = load_trajectories("{}/{}".format(LOGF, sf))
114 v[a] = (100 * count_if_exist(r[a], "traj") /
115 count_if_exist(r[a], "elap"))
116 vs = sorted(v.items(), key=lambda kv: kv[1])
118 plt.rcParams["font.size"] = 24
120 ax = fig.add_subplot(111)
121 ax.set_title("Trajectories found in 10 seconds period")
123 ax.set_ylabel("Framework tested [-]")
124 ax.set_xlabel("Found successfully [%]")
126 ax.set_yticklabels([])
129 ax.barh(j, float(i), 4, label=k)
135 def plot_mintrajcost():
136 """Plot minimum trajectory cost found."""
138 ALG=["Karaman2011", "Kuwata2008", "LaValle1998"]
139 ALGT={"Karaman2011": "RRT*",
140 "Kuwata2008": "RRT + heur",
141 "LaValle1998": "RRT"}
151 r["{}, {}, {}".format(ALGT[a], STT[st], COT[co])] = (
152 load_trajectories("{}/{}st{}co{}_lpar".format(
157 v[a] = get_lasts_if_exist(r[a], "cost")
159 #plt.rcParams["font.size"] = 24
161 for i in range(len(r.keys())):
162 ax = fig.add_subplot(3, 1, i + 1)
163 ax.set_title("Minimum trajectory cost found in 10 seconds (sequential)")
165 ax.set_ylabel("Framework tested [-]")
166 ax.set_xlabel("Minimum trajectory cost [m]")
167 #ax.set_yticklabels([])
169 plt.bar(range(len(v[r.keys()[i]])), v[r.keys()[i]], label=r.keys()[i])
175 if __name__ == "__main__":