Hi, I want to create a live plot with relatively short update, every ~200ms.
I noticed that with small Interval update, the plot has some glitches.
If I set the Interval update > 600 it works OK.
Anyone with similar issues?
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
my_x = [1]
my_y = [1]
UPDATE_POINTS_INTERVAL = 20
app = dash.Dash(__name__)
app.layout = html.Div(
[
dcc.Graph(id='live-graph', animate=True),
dcc.Interval(
id='graph-update',
interval=1*500,
n_intervals=0
),
]
)
@app.callback(Output('live-graph', 'figure'),
[Input('graph-update', 'n_intervals')])
def update_graph_scatter(n):
xy = increment_coordinates(my_x,my_y,0)
X = xy[0]
Y = xy[1]
data = plotly.graph_objs.Scatter(
x=list(X),
y=list(Y),
name='Scatter',
mode= 'lines'
)
return {'data': [data],'layout' : go.Layout(xaxis=dict(range=[((min(X)) // UPDATE_POINTS_INTERVAL) * UPDATE_POINTS_INTERVAL,
(max(X) // UPDATE_POINTS_INTERVAL + 1) * UPDATE_POINTS_INTERVAL]),
yaxis=dict(range=[0,3]), )}
def increment_coordinates(x_list,y_list,new_y):
x_list.append(x_list[-1]+1)
y_list.append(y_list[-1] + y_list[-1] * random.uniform(-0.1, 0.1))
size = len(x_list)
if size > 100+UPDATE_POINTS_INTERVAL:
del x_list[:UPDATE_POINTS_INTERVAL]
del y_list[:UPDATE_POINTS_INTERVAL]
return [x_list,y_list]
if __name__ == '__main__':
xy = increment_coordinates(my_x,my_y,0)
app.run_server(debug=True)