summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorxengineering <me@xengineering.eu>2024-09-08 14:13:41 +0200
committerxengineering <me@xengineering.eu>2024-09-08 17:21:32 +0200
commit6973093a2b80b4fb9e216d1b3e329dd4c2badc7c (patch)
tree5902ba0477744e39df834a4f9b89860a323e0d78
parentb533a3c32ef6c0b8c425ac47b683179060810a1c (diff)
downloadfinance-py-6973093a2b80b4fb9e216d1b3e329dd4c2badc7c.tar
finance-py-6973093a2b80b4fb9e216d1b3e329dd4c2badc7c.tar.zst
finance-py-6973093a2b80b4fb9e216d1b3e329dd4c2badc7c.zip
Refactor finance.visualize.py
This introduces the plot() helper function to plot the default data format list[tuple[datetime, Decimal]] with matplotlib.
-rw-r--r--finance/visualize.py33
1 files changed, 20 insertions, 13 deletions
diff --git a/finance/visualize.py b/finance/visualize.py
index a13ac22..2c70f59 100644
--- a/finance/visualize.py
+++ b/finance/visualize.py
@@ -8,19 +8,26 @@ def display(
simulated: list[tuple[datetime, Decimal]],
measured: list[tuple[datetime, Decimal]],
) -> None:
- matplotlib.pyplot.plot(
- [i[0] for i in simulated], # type: ignore
- [float(i[1]) for i in simulated],
- label="Simulated",
- )
- matplotlib.pyplot.plot(
- [i[0] for i in measured], # type: ignore
- [float(i[1]) for i in measured],
- label="Measured",
- marker="x",
- linestyle="None",
- )
- matplotlib.pyplot.xlabel("Time")
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,
+ )