From: Jiri Vlasak Date: Fri, 21 Dec 2018 07:06:11 +0000 (+0100) Subject: Refactor plot maxtime in gplot X-Git-Tag: v0.4.0~9^2~5 X-Git-Url: http://rtime.felk.cvut.cz/gitweb/hubacji1/iamcar.git/commitdiff_plain/2ba0e5ea1cba45c2dc6a6a50701ecbed4e61eab8 Refactor plot maxtime in gplot - Change the data structure of LOG. - Load logs (trajectories) in main. --- diff --git a/gplot.py b/gplot.py index 0052d67..7f34fa4 100644 --- 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()