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)))
36 ax = fig.add_subplot(111)
37 #ax.set_aspect("equal")
39 #ax.set_title("TITLE")
40 #ax.set_xlabel("Time [s]")
41 #ax.set_ylabel("YLABEL")
45 #plt.plot(xcoords, ycoords, color="blue", label="LABEL")
46 #plt.hist(vals) # log=?, range=[?], bins=?
47 #ax.bar(xvals, yvals) # width=?
48 #ax.set_xticklabels(xvals, rotation=90)
51 #plt.savefig("WHATEVER")
53 def count_if_exist(trajectories, what):
54 """From multiple trajectories compute the number of occurences.
57 trajectories -- The list of trajectories.
58 what -- Number of occurences of what to compute.
61 for t in trajectories:
69 if __name__ == "__main__":
70 """Plot success rate of single/multi-core implementations."""
71 ALG=["Karaman2011", "Kuwata2008", "LaValle1998"]
72 ALGT={"Karaman2011": "RRT*",
73 "Kuwata2008": "RRT + heur",
76 STT={"3": "R&S", "4": "Sim"}
78 COT={"1": "E2", "2": "R&S"}
84 r["{}, {}, {}".format(ALGT[a], STT[st], COT[co])] = (
85 load_trajectories("logs_sq/{}st{}co{}_lpar".format(
87 load_trajectories("logs_sq/{}st{}co{}_rper".format(
92 v[a] = (100 * count_if_exist(r[a], "traj") /
93 count_if_exist(r[a], "elap"))
94 vs = sorted(v.items(), key=lambda kv: kv[1])
96 plt.rcParams["font.size"] = 24
98 ax = fig.add_subplot(111)
99 ax.set_title("Trajectories found in 20 seconds period (sequential)")
101 ax.set_ylabel("Framework tested [-]")
102 ax.set_xlabel("Found successfully [%]")
104 ax.set_yticklabels([])
107 ax.barh(j, float(i), 4, label=k)