Update plot

This commit is contained in:
Edgar P. Burkhart 2022-05-24 15:37:58 +02:00
parent 0437814725
commit d9abdf798f
Signed by: edpibu
GPG key ID: 9833D3C5A25BD227

View file

@ -185,10 +185,25 @@ def snapshot_graph(request, uuid):
.values("category") .values("category")
.annotate(sum=models.Sum("value")) .annotate(sum=models.Sum("value"))
) )
_categories = (
_snapshot.transactions.values("category")
.annotate(sum=models.Sum("value"))
.order_by("-sum")
)
print(_categories_p) print(_categories_p)
print(_categories_m) print(_categories_m)
fig, ax = plt.subplots(constrained_layout=True) 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( ax.barh(
[ [
"*" if (c := _cat["category"]) is None else Category.objects.get(id=c).name "*" 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], [_cat["sum"] for _cat in _categories_p],
color="#007339", color="#007339",
zorder=9,
) )
ax.barh( ax.barh(
[ [
@ -204,6 +220,7 @@ def snapshot_graph(request, uuid):
], ],
[_cat["sum"] for _cat in _categories_m], [_cat["sum"] for _cat in _categories_m],
color="#bf1500", color="#bf1500",
zorder=9,
) )
ax.grid(color="k", alpha=0.2) ax.grid(color="k", alpha=0.2)
ax.set(xlabel="Value (€)") ax.set(xlabel="Value (€)")