Add titles to charts
This commit is contained in:
parent
6740993535
commit
aa06e17dcf
@ -5,12 +5,21 @@ from typing import List
|
|||||||
|
|
||||||
class CandlestickChart(Chart):
|
class CandlestickChart(Chart):
|
||||||
|
|
||||||
def __init__(self, x: Series, opens: Series, highs: Series, lows: Series, closes: Series):
|
def __init__(
|
||||||
|
self,
|
||||||
|
x: Series,
|
||||||
|
opens: Series,
|
||||||
|
highs: Series,
|
||||||
|
lows: Series,
|
||||||
|
closes: Series,
|
||||||
|
title: str = ''
|
||||||
|
):
|
||||||
self.x = x
|
self.x = x
|
||||||
self.opens = opens
|
self.opens = opens
|
||||||
self.highs = highs
|
self.highs = highs
|
||||||
self.lows = lows
|
self.lows = lows
|
||||||
self.closes = closes
|
self.closes = closes
|
||||||
|
self.title = title
|
||||||
|
|
||||||
def traces(self) -> List[Candlestick]:
|
def traces(self) -> List[Candlestick]:
|
||||||
return [Candlestick(
|
return [Candlestick(
|
||||||
|
@ -13,6 +13,7 @@ candlestick_chart = CandlestickChart(
|
|||||||
opens = data['Open'],
|
opens = data['Open'],
|
||||||
highs = data['High'],
|
highs = data['High'],
|
||||||
lows = data['Low'],
|
lows = data['Low'],
|
||||||
closes = data['Close']
|
closes = data['Close'],
|
||||||
|
title = 'SPX'
|
||||||
)
|
)
|
||||||
plot(candlestick_chart)
|
plot(candlestick_chart)
|
1
chart.py
1
chart.py
@ -5,6 +5,7 @@ from typing import List
|
|||||||
class Chart:
|
class Chart:
|
||||||
|
|
||||||
x: Series = None
|
x: Series = None
|
||||||
|
title: str = None
|
||||||
|
|
||||||
def traces(self) -> List[BaseTraceType]:
|
def traces(self) -> List[BaseTraceType]:
|
||||||
pass
|
pass
|
||||||
|
@ -5,9 +5,10 @@ from typing import List
|
|||||||
|
|
||||||
class LineChart(Chart):
|
class LineChart(Chart):
|
||||||
|
|
||||||
def __init__(self, x: Series, values: List[Series]):
|
def __init__(self, x: Series, values: List[Series], title: str = ''):
|
||||||
self.x = x
|
self.x = x
|
||||||
self.values = values
|
self.values = values
|
||||||
|
self.title = title
|
||||||
|
|
||||||
def traces(self) -> List[Scatter]:
|
def traces(self) -> List[Scatter]:
|
||||||
traces = []
|
traces = []
|
||||||
|
@ -10,6 +10,7 @@ data = ohlc('SPX.XO', '1d', start_date = start_date, end_date = end_date)
|
|||||||
|
|
||||||
line_chart = LineChart(
|
line_chart = LineChart(
|
||||||
x = data['Timestamp'],
|
x = data['Timestamp'],
|
||||||
values = [data['Close']]
|
values = [data['Close']],
|
||||||
|
title = 'SPX (Close)'
|
||||||
)
|
)
|
||||||
plot(line_chart)
|
plot(line_chart)
|
@ -10,6 +10,7 @@ data = ohlc('SPX.XO', '1d', start_date = start_date, end_date = end_date)
|
|||||||
|
|
||||||
line_chart = LineChart(
|
line_chart = LineChart(
|
||||||
x = data['Timestamp'],
|
x = data['Timestamp'],
|
||||||
values = [data['High'], data['Low']]
|
values = [data['High'], data['Low']],
|
||||||
|
title = 'SPX (High, Low)'
|
||||||
)
|
)
|
||||||
plot(line_chart)
|
plot(line_chart)
|
11
plot.py
11
plot.py
@ -3,11 +3,18 @@ from plotly.graph_objects import Figure
|
|||||||
from plotly.subplots import make_subplots
|
from plotly.subplots import make_subplots
|
||||||
from typing import List
|
from typing import List
|
||||||
|
|
||||||
|
def subplot_titles(subplots: List[List[Chart]]) -> List[str]:
|
||||||
|
subplot_titles = []
|
||||||
|
for row in subplots:
|
||||||
|
for chart in row:
|
||||||
|
subplot_titles.append(chart.title)
|
||||||
|
return subplot_titles
|
||||||
|
|
||||||
def figure_with_subplots(subplots: List[List[Chart]]) -> Figure:
|
def figure_with_subplots(subplots: List[List[Chart]]) -> Figure:
|
||||||
num_rows = len(subplots)
|
num_rows = len(subplots)
|
||||||
num_columns = len(subplots[0])
|
num_columns = len(subplots[0])
|
||||||
|
|
||||||
figure = make_subplots(rows = num_rows, cols = num_columns)
|
figure = make_subplots(rows = num_rows, cols = num_columns, subplot_titles = subplot_titles(subplots))
|
||||||
|
|
||||||
for i, row in enumerate(subplots, start = 1):
|
for i, row in enumerate(subplots, start = 1):
|
||||||
for j, chart in enumerate(row, start = 1):
|
for j, chart in enumerate(row, start = 1):
|
||||||
|
Loading…
Reference in New Issue
Block a user