summaryrefslogtreecommitdiff
path: root/finance/visualize.py
blob: 2c70f5994e363f355c12898321007fc6b371a46e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
from datetime import datetime
from decimal import Decimal

import matplotlib.pyplot


def display(
    simulated: list[tuple[datetime, Decimal]],
    measured: list[tuple[datetime, Decimal]],
) -> None:
    matplotlib.pyplot.ylabel("Money")
    matplotlib.pyplot.xlabel("Time")

    plot(data=simulated, label="Simulated")
    plot(data=measured, label="Measured", marker=".", linestyle="none")
    matplotlib.pyplot.legend()

    matplotlib.pyplot.show()


def plot(
    data: list[tuple[datetime, Decimal]],
    label: str,
    marker: str = "",
    linestyle: str = "solid",
) -> None:
    matplotlib.pyplot.plot(
        [i[0] for i in data],  # type: ignore
        [float(i[1]) for i in data],
        label=label,
        marker=marker,
        linestyle=linestyle,
    )