Updating a graph

Hi Everyone,

I am trying to create a graph that can be updated whenever a new data point is recorded.
As a bare example I am reading in the newly added characters ti var/log/system.log file and trying to plot that.
Now anytime a new data point is added a new window is opened in the browser which is annoying. Is there a way to do something like ‘‘hold on’’? Code is copied below.

Any help is appreciated! :slight_smile:

import subprocess
import os
import time
import numpy as np
import plotly.offline as py
import plotly.graph_objs as go

l=[]
n=np.zeros(shape=(300,1))
i = 0
while i < 300:

mytext1 = len(str(subprocess.check_output(['cat', '/var/log/system.log']),'ascii'))
time.sleep(5)
mytext2 = len(str(subprocess.check_output(['cat', '/var/log/system.log']),'ascii'))
n[[i,1]]=mytext2-mytext1
i = i+1
# l.append(mytext2-mytext1) 
trace = go.Scatter(
x = np.arange(i),
y = n[0:i,0]

)
# print(y)
data = [trace]

py.plot(data, filename='basic-line.html')

Hi @bencealmasi,

I’d recommend tackling this using Dash. Here’s a documentation page on updating a figure with Live data. data https://dash.plot.ly/live-updates.

If you’d like the output to be displayed in the Jupyter Notebook then you could also use a FigureWidget and then use property assignment to directly update the trace data. See https://plot.ly/python/figurewidget/

Hope that helps get you started!
-Jon