]> rtime.felk.cvut.cz Git - hubacji1/iamcar2.git/commitdiff
Use the last of what list as legend for barplot
authorJiri Vlasak <hubacji1@fel.cvut.cz>
Thu, 13 Feb 2020 17:35:34 +0000 (18:35 +0100)
committerJiri Vlasak <hubacji1@fel.cvut.cz>
Fri, 14 Feb 2020 11:40:13 +0000 (12:40 +0100)
scripts/plot.py

index 48d4113a974a13d1372310cdf8bdfb87dba2c4eb..cb11a3a2c279ad4447f0290633fc931ff5b5d62a 100644 (file)
@@ -26,8 +26,10 @@ def barplot(wl=[], t=""):
     wl -- What to plot list.
     t -- Graph title.
     """
-    if len(wl) <= 0:
+    if len(wl) < 1:
         raise ValueError
+    elif len(wl) == 1:
+        wl.append([])
     f, ax = plt.subplots()
     ax.set_title(t)
     w = wl[0]
@@ -37,7 +39,7 @@ def barplot(wl=[], t=""):
         tick_label=[k for k, v in w.items()],
         width=1 / (len(wl) + 1),
     )
-    for i in range(1, len(wl)):
+    for i in range(1, len(wl) - 1):
         w = wl[i]
         ax.bar(
             [j + i * 1/len(wl) for j in range(len(w))],
@@ -47,6 +49,7 @@ def barplot(wl=[], t=""):
     ax.minorticks_on()
     ax.grid(which="major", linestyle="-", linewidth="0.5", color="gray")
     ax.grid(which="minor", linestyle=":", linewidth="0.5", color="gray")
+    plt.legend(wl[-1])
     plt.show()
 
 def histplot(w={}, t=""):