From 23d5ffb391620d1f1d5d35404491914eb4333b81 Mon Sep 17 00:00:00 2001 From: moshferatu Date: Tue, 30 Jan 2024 11:16:06 -0800 Subject: [PATCH] Expose plotting logic in a local Python module --- candlestick_chart_example.py | 4 +--- line_chart_example.py | 5 +---- multi_line_chart_example.py | 5 +---- plotting/__init__.py | 5 +++++ backtest_chart.py => plotting/backtest_chart.py | 3 ++- .../candlestick_chart.py | 3 ++- chart.py => plotting/chart.py | 0 line.py => plotting/line.py | 0 line_chart.py => plotting/line_chart.py | 5 +++-- plot.py => plotting/plot.py | 3 ++- setup.py | 12 ++++++++++++ subplot_example.py | 6 +----- 12 files changed, 30 insertions(+), 21 deletions(-) create mode 100644 plotting/__init__.py rename backtest_chart.py => plotting/backtest_chart.py (96%) rename candlestick_chart.py => plotting/candlestick_chart.py (97%) rename chart.py => plotting/chart.py (100%) rename line.py => plotting/line.py (100%) rename line_chart.py => plotting/line_chart.py (92%) rename plot.py => plotting/plot.py (98%) create mode 100644 setup.py diff --git a/candlestick_chart_example.py b/candlestick_chart_example.py index 792928d..d15fb5d 100644 --- a/candlestick_chart_example.py +++ b/candlestick_chart_example.py @@ -1,8 +1,6 @@ from database.ohlc import ohlc from datetime import datetime, timedelta - -from candlestick_chart import CandlestickChart -from plot import plot +from plotting import CandlestickChart, plot end_date = datetime.today().date() start_date = (end_date - timedelta(days = 90)) diff --git a/line_chart_example.py b/line_chart_example.py index e52947b..bb31dbb 100644 --- a/line_chart_example.py +++ b/line_chart_example.py @@ -1,9 +1,6 @@ from database.ohlc import ohlc from datetime import datetime, timedelta - -from line import Line -from line_chart import LineChart -from plot import plot +from plotting import Line, LineChart, plot end_date = datetime.today().date() start_date = (end_date - timedelta(days = 90)) diff --git a/multi_line_chart_example.py b/multi_line_chart_example.py index 53055b6..87cd8c7 100644 --- a/multi_line_chart_example.py +++ b/multi_line_chart_example.py @@ -1,9 +1,6 @@ from database.ohlc import ohlc from datetime import datetime, timedelta - -from line import Line -from line_chart import LineChart -from plot import plot +from plotting import Line, LineChart, plot end_date = datetime.today().date() start_date = (end_date - timedelta(days = 90)) diff --git a/plotting/__init__.py b/plotting/__init__.py new file mode 100644 index 0000000..70caed6 --- /dev/null +++ b/plotting/__init__.py @@ -0,0 +1,5 @@ +from .backtest_chart import BacktestChart +from .candlestick_chart import CandlestickChart +from .line import Line +from .line_chart import LineChart +from .plot import figure_with_subplots, plot \ No newline at end of file diff --git a/backtest_chart.py b/plotting/backtest_chart.py similarity index 96% rename from backtest_chart.py rename to plotting/backtest_chart.py index d8ef8e3..550ebf6 100644 --- a/backtest_chart.py +++ b/plotting/backtest_chart.py @@ -1,9 +1,10 @@ -from chart import Chart from numpy import where from pandas import Series from plotly.graph_objects import Bar from typing import List +from .chart import Chart + class BacktestChart(Chart): def __init__( diff --git a/candlestick_chart.py b/plotting/candlestick_chart.py similarity index 97% rename from candlestick_chart.py rename to plotting/candlestick_chart.py index f31f475..c748e41 100644 --- a/candlestick_chart.py +++ b/plotting/candlestick_chart.py @@ -1,8 +1,9 @@ -from chart import Chart from pandas import Series from plotly.graph_objects import Candlestick from typing import List +from .chart import Chart + class CandlestickChart(Chart): def __init__( diff --git a/chart.py b/plotting/chart.py similarity index 100% rename from chart.py rename to plotting/chart.py diff --git a/line.py b/plotting/line.py similarity index 100% rename from line.py rename to plotting/line.py diff --git a/line_chart.py b/plotting/line_chart.py similarity index 92% rename from line_chart.py rename to plotting/line_chart.py index 69940ae..3442175 100644 --- a/line_chart.py +++ b/plotting/line_chart.py @@ -1,9 +1,10 @@ -from chart import Chart -from line import Line from pandas import Series from plotly.graph_objects import Scatter from typing import List +from .chart import Chart +from .line import Line + class LineChart(Chart): def __init__(self, x: Series, lines: List[Line], title: str = ''): diff --git a/plot.py b/plotting/plot.py similarity index 98% rename from plot.py rename to plotting/plot.py index 3d107c3..1e2f9ee 100644 --- a/plot.py +++ b/plotting/plot.py @@ -1,8 +1,9 @@ -from chart import Chart from plotly.graph_objects import Figure from plotly.subplots import make_subplots from typing import List +from .chart import Chart + def subplot_titles(subplots: List[List[Chart]]) -> List[str]: subplot_titles = [] for row in subplots: diff --git a/setup.py b/setup.py new file mode 100644 index 0000000..db209f5 --- /dev/null +++ b/setup.py @@ -0,0 +1,12 @@ +from setuptools import setup, find_packages + +setup( + name="plotting", + version="1.0", + packages=find_packages(), + install_requires=[ + 'numpy', + 'pandas', + 'plotly' + ], +) \ No newline at end of file diff --git a/subplot_example.py b/subplot_example.py index 2bfdb21..f1956bf 100644 --- a/subplot_example.py +++ b/subplot_example.py @@ -1,10 +1,6 @@ from database.ohlc import ohlc from datetime import datetime, timedelta - -from candlestick_chart import CandlestickChart -from line import Line -from line_chart import LineChart -from plot import figure_with_subplots +from plotting import CandlestickChart, figure_with_subplots, Line, LineChart end_date = datetime.today().date() start_date = (end_date - timedelta(days = 90))