Streaming stops after around 300 updates

Hi,

I’m implementing a realtime streaming plot with bokeh.

The code below can live update the plot, but the plot stop to update after around 300 steps.

I can not figure out what’s the problem there.

BTW, i’m using the latest version of bokeh on Python 2.7.3

#!/usr/bin/env python
# -*- coding: utf-8 -*-

import numpy as np

from bokeh.client import push_session
from bokeh.plotting import figure, curdoc, reset_output
from bokeh.models import Range1d
from bokeh.io import save

x = np.array([])
y = np.array([])

p1 = figure(plot_width=1000, plot_height=200, title="bleu")
r2 = p1.line(x, y, line_width=1)
r3 = p1.scatter(x, y, size=5)

p2 = figure(plot_width=1000, plot_height=200, title="reward")
r4 = p2.line(x, y, line_width=1)
r5 = p2.scatter(x, y, size=5)

# open a session to keep our local document in sync with server
doc = curdoc()
session = push_session(doc, session_id="test1", url="http://xxx.com:5006")

session.document.add_root(p1)
session.document.add_root(p2)
import time

for d in range(1000):
    # updating a single column of the the *same length* is OK
    rand_num = np.random.rand()*10
    rand_num2 = np.random.rand()*10
    r2.data_source.stream({"x":[d], "y":[rand_num2]})
    r3.data_source.stream({"x":[d], "y":[rand_num2]})
    r4.data_source.stream({"x":[d], "y":[rand_num2]})
    r5.data_source.stream({"x":[d], "y":[rand_num2]})
    p1.x_range = Range1d(0, d + 100)
    p2.x_range = Range1d(0, d + 100)
    time.sleep(0.1)

``

Hey Raphael,

I’m not sure why your code stops working after a certain number of updates. A simpler solution to your problem might be using the add_periodic_callback() method with predefined ColumnDataSource objects for each of your figures. Here’s an example based on your code using a periodic callback that you can run with the terminal command bokeh serve --show scriptname.py:

import numpy as np
from bokeh.plotting import figure
from bokeh.models import ColumnDataSource
from bokeh.layouts import column
from [bokeh.io](http://bokeh.io) import curdoc
x = np.array([])
y = np.array([])
source1 = ColumnDataSource({'x': x, 'y': y})
source2 = ColumnDataSource({'x': x, 'y'
: y})
p1 = figure(plot_width=1000, plot_height=200, title="bleu")
p1.line('x', 'y', line_width=1, source=source1)
p1.scatter('x', 'y', size=5
, source=source1)
p2 = figure(plot_width=1000, plot_height=200, title="reward")
p2.line('x', 'y', line_width=1, source=source2)
p2.scatter('x', 'y', size=5
, source=source2)
d = 0

def update():
    global d
rand_num1 = np.random.rand()*10
    rand_num2 = np.random.rand()*10
    source1.stream({'x': [d], 'y'    : [rand_num1]})
source2.stream({'x': [d], 'y'    : [rand_num2]})
d += 1

curdoc().add_root(column(p1, p2))
curdoc().add_periodic_callback(update, 100)

···

On Sat, Feb 18, 2017 at 12:35 AM, [email protected] wrote:

Hi,

I’m implementing a realtime streaming plot with bokeh.

The code below can live update the plot, but the plot stop to update after around 300 steps.

I can not figure out what’s the problem there.

BTW, i’m using the latest version of bokeh on Python 2.7.3

#!/usr/bin/env python
# -*- coding: utf-8 -*-

import numpy as np

from bokeh.client import push_session
from bokeh.plotting import figure, curdoc, reset_output
from bokeh.models import Range1d
from bokeh.io import save

x = np.array([])
y = np.array([])

p1 = figure(plot_width=1000, plot_height=200, title="bleu")
r2 = p1.line(x, y, line_width=1)
r3 = p1.scatter(x, y, size=5)

p2 = figure(plot_width=1000, plot_height=200, title="reward")
r4 = p2.line(x, y, line_width=1)
r5 = p2.scatter(x, y, size=5)


# open a session to keep our local document in sync with server
doc = curdoc()
session = push_session(doc, session_id="test1", url="[http://xxx.com](http://xxx.com):5006")

session.document.add_root(p1)
session.document.add_root(p2)
import time

for d in range(1000):
    # updating a single column of the the *same length* is OK
    rand_num = np.random.rand()*10
    rand_num2 = np.random.rand()*10
    r2.data_source.stream({"x":[d], "y":[rand_num2]})
    r3.data_source.stream({"x":[d], "y":[rand_num2]})
    r4.data_source.stream({"x":[d], "y":[rand_num2]})
    r5.data_source.stream({"x":[d], "y":[rand_num2]})
    p1.x_range = Range1d(0, d + 100)
    p2.x_range = Range1d(0, d + 100)
    time.sleep(0.1)

``

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/f664395d-9b15-4269-b60f-d49cfa22d893%40continuum.io.

For more options, visit https://groups.google.com/a/continuum.io/d/optout.