Plotting real time streaming data with a bokeh app

Hi,

I’m trying to plot real time data with a bokeh app. The below code does not work. Need some more understanding of what is it that I’m missing.

My code -

from numpy import pi
from random import shuffle
from bokeh.client import push_session
from bokeh.plotting import figure, curdoc

x = [1,2,3]
y = [10,20,30]

p = figure()
# r1 = p.line([0, 4*pi], [-1, 1], color="firebrick")
r2 = p.line(x, y, color="navy", line_width=4)

# open a session to keep our local document in sync with server
session = push_session(curdoc())

def update():
    r2.data_source.data["y"] = shuffle(y)
    # r2.glyph.line_alpha = 1 - 0.8 * abs(step)

curdoc().add_periodic_callback(update, 50)

session.show() # open the document in a browser

session.loop_until_closed() # run forever

Here is the original code from Bokeh Docs which works absolutely fine.

import numpy as np
from numpy import pi

from bokeh.client import push_session
from bokeh.driving import cosine
from bokeh.plotting import figure, curdoc

x = np.linspace(0, 4*pi, 80)
y = np.sin(x)

p = figure()
r1 = p.line([0, 4*pi], [-1, 1], color="firebrick")
r2 = p.line(x, y, color="navy", line_width=4)

# open a session to keep our local document in sync with server
session = push_session(curdoc())

@cosine(w=0.03)
def update(step):
    r2.data_source.data["y"] = y * step
    r2.glyph.line_alpha = 1 - 0.8 * abs(step)

curdoc().add_periodic_callback(update, 50)

session.show() # open the document in a browser

session.loop_until_closed() # run forever

Shuffle returns
None. It shuffles the list in place.

Have you tried

shuffle(y)

      r2.data_source.data["y"] = y
···

On 5/12/16 9:29 AM, Veenit Shah wrote:

Hi,

      I'm trying to plot real time data with a bokeh app. The

below code does not work. Need some more understanding of what
is it that I’m missing.

My code -

from numpy import pi
from random import shuffle
from bokeh.client import push_session
from bokeh.plotting import
figure, curdoc
x = [1,2,3]
y = [10,20,30
]
p = figure()
# r1 = p.line([0, 4*pi], [-1, 1], color="firebrick")
r2 = p.line(x, y, color="navy", line_width=4
)
# open a session to keep our local document in sync with server

session = push_session(curdoc())
def     update():
r2.data_source.data["y"    ] = shuffle(y)
# r2.glyph.line_alpha = 1 - 0.8 * abs(step)

curdoc().add_periodic_callback(update, 50
)
session.show() # open the document in a browser

session.loop_until_closed() # run forever
      Here is the original code from

which works absolutely fine.

import numpy as np
from numpy import pi

from bokeh.client import push_session
from bokeh.driving import cosine
from bokeh.plotting import figure, curdoc

x = np.linspace(0, 4*pi, 80)
y = np.sin(x)

p = figure()
r1 = p.line([0, 4*pi], [-1, 1], color="firebrick")
r2 = p.line(x, y, color="navy", line_width=4)

# open a session to keep our local document in sync with server
session = push_session(curdoc())

@cosine(w=0.03)
def update(step):
    r2.data_source.data["y"] = y * step
    r2.glyph.line_alpha = 1 - 0.8 * abs(step)

curdoc().add_periodic_callback(update, 50)

session.show() # open the document in a browser

session.loop_until_closed() # run forever

  You received this message because you are subscribed to the Google

Groups “Bokeh Discussion - Public” group.

  To unsubscribe from this group and stop receiving emails from it,

send an email to [email protected].

  To post to this group, send email to [email protected].

  To view this discussion on the web visit [](https://groups.google.com/a/continuum.io/d/msgid/bokeh/fe6f6904-4872-4f29-bf76-8a921e50512c%40continuum.io?utm_medium=email&utm_source=footer)      .

For more options, visit .


Sarah Bird
Developer, Bokeh

    [
      ![Continuum Analytics](http://docs.continuum.io/_static/img/ContinuumWordmark.png)
    ](http://continuum.io)

http://bokeh.pydata.org/en/0.11.0/docs/user_guide/server.html#userguide-server-output-serverhttps://groups.google.com/a/continuum.io/d/msgid/bokeh/fe6f6904-4872-4f29-bf76-8a921e50512c%40continuum.io
https://groups.google.com/a/continuum.io/d/optout