]> rtime.felk.cvut.cz Git - hubacji1/iamcar.git/commitdiff
Refactor plot maxtime in gplot
authorJiri Vlasak <hubacji1@fel.cvut.cz>
Fri, 21 Dec 2018 07:06:11 +0000 (08:06 +0100)
committerJiri Vlasak <hubacji1@fel.cvut.cz>
Fri, 21 Dec 2018 08:56:35 +0000 (09:56 +0100)
- Change the data structure of LOG.
- Load logs (trajectories) in main.

gplot.py

index 0052d6781cca842f2b3d93dc89bc857932e762e4..7f34fa4cdc128731625172965a7ce74ea7af6875 100644 (file)
--- a/gplot.py
+++ b/gplot.py
@@ -6,16 +6,14 @@ from os import listdir
 from sys import argv, exit
 import numpy as np
 
-LOGF="log"
-LOGSF=["T2","T3", "Klemm2015"]
-LEG={
-    LOGSF[0]: "T2",
-    LOGSF[1]: "T3",
-    LOGSF[2]: "Klemm2015"}
-COLS={
-    LEG[LOGSF[0]]: "orange",
-    LEG[LOGSF[1]]: "red",
-    LEG[LOGSF[2]]: "blue"}
+LOGF = "log_wo"
+LOG = [
+    {"f": "rs", "c": "orange", "l": "Reeds and Shepp path length cost"},
+    {"f": "sh", "c": "blue", "l": "Reeds and Shepp same heading cost"},
+    {"f": "ed", "c": "red", "l": "Euclidean distance cost"},
+]
+
+r = {}
 
 def load_trajectory(fname):
     """Load trajectory from file.
@@ -206,12 +204,7 @@ def plot_costdist():
 
 def plot_maxtime():
     """Plot time of the last traj (the maximum time)."""
-
-    r={}
-    for sf in LOGSF:
-        r["{}".format(LEG[sf])] = load_trajectories("{}/{}".format(LOGF, sf))
-
-    v={}
+    v = {}
     for a in r.keys():
         v[a] = get_lasts_if_exist(r[a], "secs")
 
@@ -223,14 +216,18 @@ def plot_maxtime():
     ax.set_ylabel("Number of paths found [-]")
     ax.set_xlabel("Algorithm elapsed time [s]")
     ax.set_yscale("log")
-    ax.set_aspect("equal")
 
-    for a in r.keys():
-        plt.hist(v[a], alpha=0.5, label=a, bins=np.arange(0, 10, 0.1),
-                histtype="step", color=COLS[a])
+    for a in LOG:
+        plt.hist(
+                v[a["f"]],
+                alpha = 0.5,
+                label = a["l"],
+                bins = np.arange(0, 10, 0.1),
+                histtype = "step",
+                color = a["c"])
         try:
-                X_WHERE = np.percentile(v[a], [95])
-                plt.axvline(X_WHERE, lw=1, color=COLS[a], linestyle="--")
+                X_WHERE = np.percentile(v[a["f"]], [95])
+                plt.axvline(X_WHERE, lw=1, color=a["c"], linestyle="--")
         except:
                 pass
 
@@ -269,4 +266,7 @@ def print_successrate():
         print("{}: {}".format(a, v[a]))
 
 if __name__ == "__main__":
-    plot_costdist()
+    r = {}
+    for sf in [i["f"] for i in LOG]:
+        r[sf] = load_trajectories("{}/{}".format(LOGF, sf))
+    plot_maxtime()