]> rtime.felk.cvut.cz Git - hubacji1/iamcar2.git/blob - scripts/plot.py
Refactor typo, spacing
[hubacji1/iamcar2.git] / scripts / plot.py
1 """Procedures for plotting graphs."""
2 import sys
3 import matplotlib.pyplot as plt
4
5 import scenario
6
7 def boxplot(w={}, t=""):
8     """Plot boxplot graph.
9
10     Keyword arguments:
11     w -- What to plot.
12     t -- Graph title.
13     """
14     f, ax = plt.subplots()
15     ax.set_title(t)
16     ax.boxplot([v for k, v in w.items()], labels=[k for k, v in w.items()])
17     ax.minorticks_on()
18     ax.grid(which="major", linestyle="-", linewidth="0.5", color="gray")
19     ax.grid(which="minor", linestyle=":", linewidth="0.5", color="gray")
20     plt.show()
21
22 def barplot(w={}, t=""):
23     """Plot barplot graph.
24
25     Keyword arguments:
26     w -- What to plot.
27     t -- Graph title.
28     """
29     f, ax = plt.subplots()
30     ax.set_title(t)
31     ax.bar(
32         range(len(w)),
33         [v for k, v in w.items()],
34         tick_label=[k for k, v in w.items()],
35     )
36     ax.minorticks_on()
37     ax.grid(which="major", linestyle="-", linewidth="0.5", color="gray")
38     ax.grid(which="minor", linestyle=":", linewidth="0.5", color="gray")
39     plt.show()
40
41 if __name__ == "__main__":
42     if len(sys.argv) > 1:
43         w = sys.argv[1]
44     else:
45         w = "time"
46     if w == "time":
47         boxplot(scenario.time(), "Elapsed time")
48     elif w == "cost":
49         boxplot(scenario.cost(), "Final path cost")
50     elif w == "cusp":
51         boxplot(scenario.cusp(), "Changes in direction")
52     elif w == "error":
53         barplot(scenario.error_rate(), "Error rate")