Skip to content

Instantly share code, notes, and snippets.

@mathisonian
Created April 12, 2016 20:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mathisonian/62b5f4c28cf97ccb46780286c729b16f to your computer and use it in GitHub Desktop.
Save mathisonian/62b5f4c28cf97ccb46780286c729b16f to your computer and use it in GitHub Desktop.
streaming line python
from lightning import Lightning
import numpy as np
import time
from random import randint, random
lgn = Lightning()
session = lgn.create_session()
NUM_LINES = 2
NUM_INITIAL_POINTS = 10
series = [[random() for j in xrange(NUM_INITIAL_POINTS)] for i in xrange(NUM_LINES)]
print series
x = range(NUM_INITIAL_POINTS)
# full manual control
#
viz_full_control = lgn.line(series, index=x)
session.open()
while True:
new_points = [[] for i in xrange(NUM_LINES)]
# choose a line to add the new point to...
line_index = randint(0, NUM_LINES-1)
for i in xrange(len(new_points)):
if i == line_index:
# add a new random point to one of the lines
new_points[i].append(random())
else:
# re-use the last value if there is nothing new
new_points[i].append(series[i][-1])
# update the x-axis values
x.append(x[-1] + random())
for i in xrange(len(series)):
for j in xrange(len(new_points[i])):
series[i].append(new_points[i][j])
viz_full_control.update(series, index=x)
time.sleep(2)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment