]> rtime.felk.cvut.cz Git - coffee/coffee-flask.git/blobdiff - app.py
Do not show zeros in the taste graph
[coffee/coffee-flask.git] / app.py
diff --git a/app.py b/app.py
index 083114cc966db21df5086c2f24257a120b79a5c7..1c7140398a24e767eea27f3d6bab4d4a1b789bce 100644 (file)
--- a/app.py
+++ b/app.py
@@ -5,6 +5,7 @@ import numpy as np
 import matplotlib
 matplotlib.use('Agg')
 import matplotlib.pyplot as plt
+from matplotlib.ticker import MaxNLocator
 from io import BytesIO
 
 import coffee_db as db
@@ -75,8 +76,8 @@ def coffee_graph_flavors():
     fig = plt.figure(figsize=(3, 3))
     ax = fig.add_subplot(111)
     ax.set_aspect(1)
-    ax.pie(counts)
-    ax.legend(flavors)
+    ax.pie(counts, autopct=lambda p: '{:.0f}'.format(p * sum(counts)/100) if p != 0 else '')
+    ax.legend(flavors, bbox_to_anchor=(1.0, 1.0))
     ax.set_title("Your taste")
     fig.savefig(b, format="svg", bbox_inches="tight")
     b.seek(0)
@@ -133,6 +134,7 @@ def coffee_graph_history():
     ax.set_xticks(range(len(days)))
     ax.set_xticklabels(xdays)
     ax.set_title("Your week")
+    ax.yaxis.set_major_locator(MaxNLocator(integer=True))
     fig.savefig(b, format="svg", bbox_inches="tight")
     b.seek(0)
     plt.close(fig)