我正在dash应用程序中绘制一个折线图,该图经常更新,比如说每1秒更新一次,但当我尝试放大时,它会立即返回到初始视图。我做错了什么?我是dash和web ui的新手,所以任何帮助都会对我有很大帮助,提前谢谢。
import dash
from dash.dependencies import Output, Input
import dash_core_components as dcc
import dash_html_components as html
import plotly
import random
import plotly.graph_objs as go
from collections import deque
X = deque()
X.append(1)
Y = deque()
Y.append(1)
app = dash.Dash(__name__)
app.layout = html.Div(
[
dcc.Graph(id='live-graph', animate=True),
dcc.Interval(
id='graph-update',
interval=1*1000
),
]
)
@app.callback(Output('live-graph', 'figure'),
[Input('graph-update', 'n_intervals')])
def update_graph_scatter(input_data):
X.append(X[-1]+1)
Y.append(Y[-1]+Y[-1]*random.uniform(-0.1,0.1))
data = plotly.graph_objs.Scatter(
x=list(X),
y=list(Y),
name='Scatter',
mode= 'lines+markers'
)
return {'data': [data],'layout' : go.Layout(
xaxis=dict(range=[0, max(X) + 1]),
yaxis=dict(range=[min(Y) - 0.15, max(Y) + 1]),
title="Plot Title",
xaxis_title="x Axis Title",
yaxis_title="y Axis Title",
font=dict(
family="Courier New, monospace",
size=20,
color="#7f7f7f"
)
)}
if __name__ == '__main__':
app.run_server(debug=True)
暂无答案!
目前还没有任何答案,快来回答吧!