From d9abdf798fdc9882e1c43c7f48d2ad50a6037206 Mon Sep 17 00:00:00 2001 From: "Edgar P. Burkhart" Date: Tue, 24 May 2022 15:37:58 +0200 Subject: [PATCH] Update plot --- nummi/main/views.py | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/nummi/main/views.py b/nummi/main/views.py index 624f40f..05278e3 100644 --- a/nummi/main/views.py +++ b/nummi/main/views.py @@ -185,10 +185,25 @@ def snapshot_graph(request, uuid): .values("category") .annotate(sum=models.Sum("value")) ) + _categories = ( + _snapshot.transactions.values("category") + .annotate(sum=models.Sum("value")) + .order_by("-sum") + ) print(_categories_p) print(_categories_m) fig, ax = plt.subplots(constrained_layout=True) + ax.barh( + [ + "*" if (c := _cat["category"]) is None else Category.objects.get(id=c).name + for _cat in _categories + ], + [_cat["sum"] for _cat in _categories], + hatch="/", + fill=False, + zorder=10, + ) ax.barh( [ "*" if (c := _cat["category"]) is None else Category.objects.get(id=c).name @@ -196,6 +211,7 @@ def snapshot_graph(request, uuid): ], [_cat["sum"] for _cat in _categories_p], color="#007339", + zorder=9, ) ax.barh( [ @@ -204,10 +220,11 @@ def snapshot_graph(request, uuid): ], [_cat["sum"] for _cat in _categories_m], color="#bf1500", + zorder=9, ) ax.grid(color="k", alpha=0.2) ax.set(xlabel="Value (€)") - #fig.tight_layout() + # fig.tight_layout() with tempfile.NamedTemporaryFile(suffix=".svg") as f: fig.savefig(f.name) f.seek(0)