【发布时间】:2020-07-10 07:56:26
【问题描述】:
我试图在一个图中显示烛台图和折线图。我尝试通过回调更新它们,以检查 csv 文件中的新更新。在触发回调之前,它们都会正确显示。在此之后,折线图仍然显示,但烛台图变得不可见。当我调整大小或缩放时,图表会正确显示,直到它再次触发回调。我应该如何在不同的 y 轴上正确设置具有多个图形(烛台和折线图)的图形,并使用有效的回调函数。
这是我的代码:
df_btc = pd.read_csv("data/livedata.csv")
app = dash.Dash(__name__)
app.layout = html.Div(
[
html.Div([
dcc.Graph(id='live_graph', animate=True, style={"height": "100vh"}),
dcc.Interval(
id='interval_component',
interval=2000,
),
]),
],
style = {"height": "100vh"}
)
@app.callback(Output('live_graph', 'figure'),
[Input('interval_component', 'n_intervals')])
def graph_update(n):
df_btc = pd.read_csv("data/livedata.csv")
...
(parsing the data and making lists, asuming this works as it shows up initially)
...
graph_candlestick = go.Candlestick(x=list(btc_date),
open=list(btc_open),
high=list(btc_high),
low=list(btc_low),
close=list(btc_close),
xaxis="x",
yaxis="y",
visible=True)
graph_rsi = get_rsi(df_btc)
return {'data': [graph_rsi, graph_candlestick], 'layout': go.Layout(xaxis=dict(range=[min(btc_date),max(btc_date)]),
yaxis=dict(range=[min(btc_low),max(btc_high)],),
yaxis2=dict(range=[0,100], overlaying='y', side='right'),) }
def get_rsi(df_btc):
...
(calculating the data and making lists, asuming this works as it shows up initially)
...
return go.Scatter(x=list(rsi_date),
y=list(rsi),
xaxis="x1",
yaxis="y2",
visible=True,
showlegend=False)
if __name__ == '__main__':
app.run_server(debug=True)
我第一次和第二次比较了回调函数的输出。它们恰好完全相同。
【问题讨论】:
标签: plotly plotly-dash