Add methods for plotting charts, including subplots
This commit is contained in:
parent
84bc78d16d
commit
a7dd63dc0f
32
plot.py
Normal file
32
plot.py
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
from chart import Chart
|
||||||
|
from plotly.graph_objects import Figure
|
||||||
|
from plotly.subplots import make_subplots
|
||||||
|
from typing import List
|
||||||
|
|
||||||
|
def plot_with_subplots(subplots: List[List[Chart]]) -> Figure:
|
||||||
|
num_rows = len(subplots)
|
||||||
|
num_columns = len(subplots[0])
|
||||||
|
|
||||||
|
figure = make_subplots(rows = num_rows, cols = num_columns)
|
||||||
|
|
||||||
|
for i, row in enumerate(subplots, start = 1):
|
||||||
|
for j, chart in enumerate(row, start = 1):
|
||||||
|
figure.add_trace(chart.trace(), row = i, col = j)
|
||||||
|
figure.update_xaxes(showgrid = False, showticklabels = True, rangeslider = dict(visible = False), row = i, col = j)
|
||||||
|
figure.update_yaxes(showgrid = False, side = 'right', row = i, col = j)
|
||||||
|
|
||||||
|
# TODO: Make this configurable.
|
||||||
|
figure.update_layout(
|
||||||
|
paper_bgcolor = '#0f0f0f',
|
||||||
|
plot_bgcolor = '#0f0f0f',
|
||||||
|
font_color = '#7a7c7d',
|
||||||
|
showlegend = False,
|
||||||
|
margin = dict(
|
||||||
|
pad = 15
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
return figure
|
||||||
|
|
||||||
|
def plot(chart: Chart) -> Figure:
|
||||||
|
return plot_with_subplots([[chart]])
|
Loading…
Reference in New Issue
Block a user