Switch to horizontal bar plot

This commit is contained in:
Edgar P. Burkhart 2022-05-24 15:32:00 +02:00
parent b1b3a5afa2
commit 0437814725
Signed by: edpibu
GPG Key ID: 9833D3C5A25BD227
1 changed files with 5 additions and 4 deletions

View File

@ -188,8 +188,8 @@ def snapshot_graph(request, uuid):
print(_categories_p) print(_categories_p)
print(_categories_m) print(_categories_m)
fig, ax = plt.subplots() fig, ax = plt.subplots(constrained_layout=True)
ax.bar( 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
for _cat in _categories_p for _cat in _categories_p
@ -197,7 +197,7 @@ def snapshot_graph(request, uuid):
[_cat["sum"] for _cat in _categories_p], [_cat["sum"] for _cat in _categories_p],
color="#007339", color="#007339",
) )
ax.bar( 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
for _cat in _categories_m for _cat in _categories_m
@ -206,7 +206,8 @@ def snapshot_graph(request, uuid):
color="#bf1500", color="#bf1500",
) )
ax.grid(color="k", alpha=0.2) ax.grid(color="k", alpha=0.2)
ax.set(ylabel="Value (€)") ax.set(xlabel="Value (€)")
#fig.tight_layout()
with tempfile.NamedTemporaryFile(suffix=".svg") as f: with tempfile.NamedTemporaryFile(suffix=".svg") as f:
fig.savefig(f.name) fig.savefig(f.name)
f.seek(0) f.seek(0)