Update plot style

This commit is contained in:
Edgar P. Burkhart 2022-12-20 16:31:03 +01:00
parent d04fc756d4
commit b090902648
Signed by: edpibu
GPG key ID: 9833D3C5A25BD227
2 changed files with 22 additions and 6 deletions

View file

@ -6,7 +6,7 @@ figure.autolayout: True
figure.figsize: 8, 4
figure.dpi: 300
axes.prop_cycle: cycler('color', ["66cc66", "#338033", "#99ff99", "#802653", "#cc6699"])
axes.prop_cycle: cycler('color', ["66cc66", "338033", "99ff99", "802653", "cc6699"])
axes.axisbelow: True
axes.grid: True

View file

@ -69,8 +69,17 @@ def categories(request):
@login_required
def category(request, uuid):
_category = get_object_or_404(Category, id=uuid)
_values = (
_values_p = (
Transaction.objects.filter(category=_category)
.filter(value__gt=0)
.annotate(m=models.functions.TruncMonth("date"))
.values("m")
.annotate(sum=models.Sum("value"))
.order_by("m")
)
_values_m = (
Transaction.objects.filter(category=_category)
.filter(value__lt=0)
.annotate(m=models.functions.TruncMonth("date"))
.values("m")
.annotate(sum=models.Sum("value"))
@ -78,10 +87,17 @@ def category(request, uuid):
)
fig, ax = plt.subplots()
ax.step(
[v["m"] for v in _values],
[v["sum"] for v in _values],
where="post",
ax.bar(
[v["m"] for v in _values_p],
[v["sum"] for v in _values_p],
width=12,
color="#66cc66",
)
ax.bar(
[v["m"] for v in _values_m],
[v["sum"] for v in _values_m],
width=12,
color="#cc6699",
)
ax.xaxis.set_major_formatter(
mdates.ConciseDateFormatter(ax.xaxis.get_major_locator())