Extending data to the same plot


I’m new to plotly and I’m trying to update a plot (a single line that has a new point every time) when I receive my data.

The ting is, I want to start plotting before receiving all my data points and update ‘real-time’ when I get them.

The only thing close I have managed to do is:

import plotly.plotly as py
from plotly.graph_objs import *

while i<10:
    new_data = dict(x=[3+i,4+i], y=[3+i,4+i] )
    data = [ new_data ]
    i = i+1
    plot_url = py.plot(data, filename='extend plot', fileopt='extend')

However, this opens a new tab for each time py.plot is called and I can’t find a way to live update the plot in the same tab.

Thank you for the help!

Hi @bertaserracanta,

If you’re working in the Jupyter Notebook, the easiest way to do this would be to use a FigureWidget

First display a figure with an empty scatter trace

import plotly.graph_objs as go
import time
fig = go.FigureWidget(data=[go.Scatter(x=[], y=[])])

Then update the data

scatter = fig.data[0]

while i<10:
    new_x = [3+i, 4+i]
    new_y = [3+i, i-4]
    with fig.batch_update():
        scatter.x += tuple(new_x)
        scatter.y += tuple(new_y)
    i = i+1

If you’re not working in the Jupyter Notebook, and you want a standalone web app. You could also accomplish the same this using Dash https://dash.plot.ly/.

Hope that helps,


What about online mode?