streamlit / utils /plots.py
arash7920's picture
Upload 19 files
97fe216
Raw History Blame Contribute Delete
3.35 kB
from plotly.subplots import make_subplots
import plotly.graph_objects as go
def plot_multiple_columns(dataframe, primary_column, secondary_column, ternary_column=None, scale_similarity=None):
figure = make_subplots(specs=[[{"secondary_y": True}]])
figure.add_trace(go.Scatter(x=dataframe.index, y=dataframe[primary_column], name=primary_column,
line=dict(color='#FF0000', width=1)), secondary_y=False)
figure.add_trace(go.Scatter(x=dataframe.index, y=dataframe[secondary_column], name=secondary_column,
line=dict(color='#00FF00', width=1)), secondary_y=True)
if ternary_column is not None:
if scale_similarity == 1:
figure.add_trace(go.Scatter(x=dataframe.index, y=dataframe[ternary_column], name=ternary_column,
line=dict(color='#0000FF', width=1)), secondary_y=False)
elif scale_similarity == 2:
figure.add_trace(go.Scatter(x=dataframe.index, y=dataframe[ternary_column], name=ternary_column,
line=dict(color='#0000FF', width=1)), secondary_y=True)
figure.update_layout(title_text=f"{primary_column} vs {secondary_column}")
figure.update_xaxes(title_text="time")
return figure
def plot_volume_profile(main_dataframe, volume_profile):
figure = go.Figure(data=[go.Bar(x=volume_profile.Volume, y=volume_profile.Close,
orientation="h", xaxis="x", yaxis="y", visible=True, name='Volume Profile',
showlegend=False),
go.Candlestick(x=main_dataframe.index, open=main_dataframe.open, high=main_dataframe.high,
low=main_dataframe.low, close=main_dataframe.close, xaxis="x2", yaxis="y",
visible=True, showlegend=False, name='OHLCV')],
layout=go.Layout(title=go.layout.Title(text="Candlestick With Volume Profile"),
autosize=False, width=700, height=550,
xaxis=go.layout.XAxis(side="top",
showticklabels=False,
rangeslider=go.layout.xaxis.Rangeslider(visible=False)),
yaxis=go.layout.YAxis(side="left", showticklabels=False),
xaxis2=go.layout.XAxis(side="bottom", title="Date",
overlaying="x",
rangeslider=go.layout.xaxis.Rangeslider(visible=False)),
# yaxis2=go.layout.YAxis(side="left", title="Price",
# overlaying="y")
))
figure.data[0].marker.color = '#999900'
figure.data[1].increasing.fillcolor = 'rgb(230,72,72)'
figure.data[1].increasing.line.color = 'rgb(194,16,16)'
figure.data[1].decreasing.fillcolor = 'rgb(95,141,78)'
figure.data[1].decreasing.line.color = 'rgb(40,84,48)'
figure.update_layout(template="plotly_white")
return figure