在绘图短划线实时流图中保持间隔更新的缩放级别

时间:2018-08-18 10:16:07

标签: python-3.x plotly plotly-dash

我是新来的破折号。当我使用pythonprogramming.net网站上的以下示例代码练习实时流图时,遇到了此问题。由于间隔更新,放大的部分会自动重置。我的问题就是这样 https://community.plot.ly/t/solved-keep-zoom-level-on-intervald-update/4665

但是,我不知道该如何解决。谁能用代码解释我。

import dash
from dash.dependencies import Output, Event
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(maxlen=20)
X.append(1)
Y = deque(maxlen=20)
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'),
              events=[Event('graph-update', 'interval')])
def update_graph_scatter():
    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=[min(X),max(X)]),
                                                yaxis=dict(range=[min(Y),max(Y)]),)}


if __name__ == '__main__':
    app.run_server(debug=True)

0 个答案:

没有答案