diff --git a/nummi/plot/nummi.mplstyle b/nummi/plot/nummi.mplstyle index 90249c4..b49262b 100644 --- a/nummi/plot/nummi.mplstyle +++ b/nummi/plot/nummi.mplstyle @@ -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 diff --git a/nummi/plot/views.py b/nummi/plot/views.py index 5abc4d5..90ddae2 100644 --- a/nummi/plot/views.py +++ b/nummi/plot/views.py @@ -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())