Slow Graph updating

I have the code below and find that bokeh is very slow to update the graphs, is there something I am doing wrong that would allow faster updates of the graphs?

import numpy as np

from numpy import pi

import bokeh

from bokeh.client import push_session

from bokeh.driving import cosine

from bokeh.plotting import Figure, curdoc

from bokeh.models.widgets import Select

from bokeh.models import ColumnDataSource, HBox, VBoxForm

from bokeh.models.widgets import Slider, TextInput, Toggle

import re

x = [0]

y = [0]

p = Figure()

#r1 = p.line([0, 4*pi], [-1, 1], color=“firebrick”)

r2 = p.line(x, y, color=“navy”, line_width=4)

p2=Figure()

r1=p2.line(x, y, color=“red”, line_width=4)

p3=Figure()

r3=p3.line(x, y, color=“red”, line_width=4)

r3a=p3.line(x, y, color=“blue”, line_width=2)

p2.x_range=p.x_range

p3.x_range=p.x_range

def ClearGraph():

r2.data_source.data[“y”] =

r2.data_source.data[“x”] =

r1.data_source.data[“y”] =

r1.data_source.data[“x”] =

r3.data_source.data[“y”] =

r3a.data_source.data[“y”] =

r3.data_source.data[“x”] =

r3a.data_source.data[“x”] =

p2.x_range=p.x_range

p3.x_range=p.x_range

def updateGraph():

N=200000;

p.title=""

print “Data Loaded”

x1=range(N)

y1=np.random.rand(N)

c1=np.random.rand(N)

t1=np.random.rand(N)

p1=np.random.rand(N)

print “Transform done”

r2.data_source.data[“y”] = c1

r2.data_source.data[“x”] = x1

print “graph1 done”

r1.data_source.data[“y”] = y1

r1.data_source.data[“x”] = x1

print “graph2 done”

r3.data_source.data[“y”] = t1

r3a.data_source.data[“y”] = p1

r3.data_source.data[“x”] = x1

r3a.data_source.data[“x”] = x1

print “graph3 done”

p2.x_range=p.x_range

p3.x_range=p.x_range

p.title=“Done”

print len(x1)

def button_click(something):

#button.disabled=True

updateGraph()

#button.disabled=False

#print “button update”

button = Toggle(label=“Update Graph”, type=“success”)

button.on_click(button_click)

inputs = VBoxForm(children=[button])

x=VBoxForm(children=[p,p2,p3])

curdoc().add_root(HBox(children=[inputs,x], width=1000))

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(updateGraph, 30000)

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

session.loop_until_closed() # run forever

There is one thing that you are doing wrong, which is that you should really always update the .data attribute of a ColumnDataSource in a single operation, i.e., make a new dictionary up front, then set .data to that new dictionary, instead of updating keys individually:

  new_data = { # stuff }
        source.data = new_data

Doing it the way you are doing causes the server to update excessively, but also potentially violates the assumptions that all columns in a column data source are always the same length at all times.

Beyond that, sending hundreds of thousands of points to the browser is almost never going to be a good idea due to limitations of the browser. FOr larger data sets, you should look at the related bokeh/datashader library that has been used to interactively visualize hundreds of millions of points. A recent thread here has more information:

  https://groups.google.com/a/continuum.io/forum/?pli=1#!topic/bokeh/o2x7CXpuB2w

Thanks,

Bryan

···

On Jun 23, 2016, at 8:02 AM, Trampas Stern <[email protected]> wrote:

I have the code below and find that bokeh is very slow to update the graphs, is there something I am doing wrong that would allow faster updates of the graphs?

import numpy as np
from numpy import pi
import bokeh
from bokeh.client import push_session
from bokeh.driving import cosine
from bokeh.plotting import Figure, curdoc
from bokeh.models.widgets import Select
from bokeh.models import ColumnDataSource, HBox, VBoxForm
from bokeh.models.widgets import Slider, TextInput, Toggle

import re

x = [0]
y = [0]

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

p2=Figure()
r1=p2.line(x, y, color="red", line_width=4)

p3=Figure()
r3=p3.line(x, y, color="red", line_width=4)
r3a=p3.line(x, y, color="blue", line_width=2)

p2.x_range=p.x_range
p3.x_range=p.x_range

def ClearGraph():
    r2.data_source.data["y"] =
    r2.data_source.data["x"] =
    r1.data_source.data["y"] =
    r1.data_source.data["x"] =
    r3.data_source.data["y"] =
    r3a.data_source.data["y"] =
    r3.data_source.data["x"] =
    r3a.data_source.data["x"] =
    p2.x_range=p.x_range
    p3.x_range=p.x_range
    
def updateGraph():
    N=200000;
    p.title=""
    print "Data Loaded"
    x1=range(N)
    y1=np.random.rand(N)
    c1=np.random.rand(N)
    t1=np.random.rand(N)
    p1=np.random.rand(N)
    print "Transform done"
    r2.data_source.data["y"] = c1
    r2.data_source.data["x"] = x1
    print "graph1 done"
    r1.data_source.data["y"] = y1
    r1.data_source.data["x"] = x1
    print "graph2 done"
    r3.data_source.data["y"] = t1
    r3a.data_source.data["y"] = p1
    r3.data_source.data["x"] = x1
    r3a.data_source.data["x"] = x1
    print "graph3 done"
# p2.x_range=p.x_range
# p3.x_range=p.x_range
    p.title="Done"
    
    print len(x1)

def button_click(something):
    #button.disabled=True
    updateGraph()
    #button.disabled=False
    #print "button update"
    
button = Toggle(label="Update Graph", type="success")
    
button.on_click(button_click)

inputs = VBoxForm(children=[button])
x=VBoxForm(children=[p,p2,p3])
curdoc().add_root(HBox(children=[inputs,x], width=1000))
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(updateGraph, 30000)

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/CADqjcyjaAjd4skGWwD5oQQ9t_fwSjYMDNphjJgL50HLtMNKYBA%40mail.gmail.com\.
For more options, visit https://groups.google.com/a/continuum.io/d/optout\.

I am looking into datashader, but I am having trouble figuring out the canvas concept and how to use it in to my boken example.

thanks

Trampas

···

On Thu, Jun 23, 2016 at 9:11 AM, Bryan Van de Ven [email protected] wrote:

There is one thing that you are doing wrong, which is that you should really always update the .data attribute of a ColumnDataSource in a single operation, i.e., make a new dictionary up front, then set .data to that new dictionary, instead of updating keys individually:

    new_data = { # stuff }

    source.data = new_data

Doing it the way you are doing causes the server to update excessively, but also potentially violates the assumptions that all columns in a column data source are always the same length at all times.

Beyond that, sending hundreds of thousands of points to the browser is almost never going to be a good idea due to limitations of the browser. FOr larger data sets, you should look at the related bokeh/datashader library that has been used to interactively visualize hundreds of millions of points. A recent thread here has more information:

    [https://groups.google.com/a/continuum.io/forum/?pli=1#!topic/bokeh/o2x7CXpuB2w](https://groups.google.com/a/continuum.io/forum/?pli=1#!topic/bokeh/o2x7CXpuB2w)

Thanks,

Bryan

On Jun 23, 2016, at 8:02 AM, Trampas Stern [email protected] wrote:

I have the code below and find that bokeh is very slow to update the graphs, is there something I am doing wrong that would allow faster updates of the graphs?

import numpy as np

from numpy import pi

import bokeh

from bokeh.client import push_session

from bokeh.driving import cosine

from bokeh.plotting import Figure, curdoc

from bokeh.models.widgets import Select

from bokeh.models import ColumnDataSource, HBox, VBoxForm

from bokeh.models.widgets import Slider, TextInput, Toggle

import re

x = [0]

y = [0]

p = Figure()

#r1 = p.line([0, 4*pi], [-1, 1], color=“firebrick”)

r2 = p.line(x, y, color=“navy”, line_width=4)

p2=Figure()

r1=p2.line(x, y, color=“red”, line_width=4)

p3=Figure()

r3=p3.line(x, y, color=“red”, line_width=4)

r3a=p3.line(x, y, color=“blue”, line_width=2)

p2.x_range=p.x_range

p3.x_range=p.x_range

def ClearGraph():

r2.data_source.data["y"] = []
r2.data_source.data["x"] = []
r1.data_source.data["y"] = []
r1.data_source.data["x"] = []
r3.data_source.data["y"] = []
r3a.data_source.data["y"] = []
r3.data_source.data["x"] = []
r3a.data_source.data["x"] = []
p2.x_range=p.x_range
p3.x_range=p.x_range

def updateGraph():

N=200000;
p.title=""
print "Data Loaded"
x1=range(N)
y1=np.random.rand(N)
c1=np.random.rand(N)
t1=np.random.rand(N)
p1=np.random.rand(N)
print "Transform done"
r2.data_source.data["y"] = c1
r2.data_source.data["x"] = x1
print "graph1 done"
r1.data_source.data["y"] = y1
r1.data_source.data["x"] = x1
print "graph2 done"
r3.data_source.data["y"] = t1
r3a.data_source.data["y"] = p1
r3.data_source.data["x"] = x1
r3a.data_source.data["x"] = x1
print "graph3 done"

p2.x_range=p.x_range

p3.x_range=p.x_range

p.title="Done"
print len(x1)

def button_click(something):

#button.disabled=True
updateGraph()
#button.disabled=False
#print "button update"

button = Toggle(label=“Update Graph”, type=“success”)

button.on_click(button_click)

inputs = VBoxForm(children=[button])

x=VBoxForm(children=[p,p2,p3])

curdoc().add_root(HBox(children=[inputs,x], width=1000))

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(updateGraph, 30000)

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/CADqjcyjaAjd4skGWwD5oQQ9t_fwSjYMDNphjJgL50HLtMNKYBA%40mail.gmail.com.

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

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/998C435A-7908-4B61-B5C5-AE42E455BC47%40continuum.io.

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

I have watched the video and went through the examples on datashader but I still can not get it to work. I have not figured out how to link the datashader output to a bokeh figure.

Additionally I have not figured out how to get a datashader to plot a line instead of points.

···

On Thu, Jun 23, 2016 at 1:40 PM, Trampas Stern [email protected] wrote:

I am looking into datashader, but I am having trouble figuring out the canvas concept and how to use it in to my boken example.

thanks

Trampas

On Thu, Jun 23, 2016 at 9:11 AM, Bryan Van de Ven [email protected] wrote:

There is one thing that you are doing wrong, which is that you should really always update the .data attribute of a ColumnDataSource in a single operation, i.e., make a new dictionary up front, then set .data to that new dictionary, instead of updating keys individually:

    new_data = { # stuff }

    source.data = new_data

Doing it the way you are doing causes the server to update excessively, but also potentially violates the assumptions that all columns in a column data source are always the same length at all times.

Beyond that, sending hundreds of thousands of points to the browser is almost never going to be a good idea due to limitations of the browser. FOr larger data sets, you should look at the related bokeh/datashader library that has been used to interactively visualize hundreds of millions of points. A recent thread here has more information:

    [https://groups.google.com/a/continuum.io/forum/?pli=1#!topic/bokeh/o2x7CXpuB2w](https://groups.google.com/a/continuum.io/forum/?pli=1#!topic/bokeh/o2x7CXpuB2w)

Thanks,

Bryan

On Jun 23, 2016, at 8:02 AM, Trampas Stern [email protected] wrote:

I have the code below and find that bokeh is very slow to update the graphs, is there something I am doing wrong that would allow faster updates of the graphs?

import numpy as np

from numpy import pi

import bokeh

from bokeh.client import push_session

from bokeh.driving import cosine

from bokeh.plotting import Figure, curdoc

from bokeh.models.widgets import Select

from bokeh.models import ColumnDataSource, HBox, VBoxForm

from bokeh.models.widgets import Slider, TextInput, Toggle

import re

x = [0]

y = [0]

p = Figure()

#r1 = p.line([0, 4*pi], [-1, 1], color=“firebrick”)

r2 = p.line(x, y, color=“navy”, line_width=4)

p2=Figure()

r1=p2.line(x, y, color=“red”, line_width=4)

p3=Figure()

r3=p3.line(x, y, color=“red”, line_width=4)

r3a=p3.line(x, y, color=“blue”, line_width=2)

p2.x_range=p.x_range

p3.x_range=p.x_range

def ClearGraph():

r2.data_source.data["y"] = []
r2.data_source.data["x"] = []
r1.data_source.data["y"] = []
r1.data_source.data["x"] = []
r3.data_source.data["y"] = []
r3a.data_source.data["y"] = []
r3.data_source.data["x"] = []
r3a.data_source.data["x"] = []
p2.x_range=p.x_range
p3.x_range=p.x_range

def updateGraph():

N=200000;
p.title=""
print "Data Loaded"
x1=range(N)
y1=np.random.rand(N)
c1=np.random.rand(N)
t1=np.random.rand(N)
p1=np.random.rand(N)
print "Transform done"
r2.data_source.data["y"] = c1
r2.data_source.data["x"] = x1
print "graph1 done"
r1.data_source.data["y"] = y1
r1.data_source.data["x"] = x1
print "graph2 done"
r3.data_source.data["y"] = t1
r3a.data_source.data["y"] = p1
r3.data_source.data["x"] = x1
r3a.data_source.data["x"] = x1
print "graph3 done"

p2.x_range=p.x_range

p3.x_range=p.x_range

p.title="Done"
print len(x1)

def button_click(something):

#button.disabled=True
updateGraph()
#button.disabled=False
#print "button update"

button = Toggle(label=“Update Graph”, type=“success”)

button.on_click(button_click)

inputs = VBoxForm(children=[button])

x=VBoxForm(children=[p,p2,p3])

curdoc().add_root(HBox(children=[inputs,x], width=1000))

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(updateGraph, 30000)

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/CADqjcyjaAjd4skGWwD5oQQ9t_fwSjYMDNphjJgL50HLtMNKYBA%40mail.gmail.com.

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

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/998C435A-7908-4B61-B5C5-AE42E455BC47%40continuum.io.

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

The datashader time series example (https://anaconda.org/jbednar/tseries/notebook) shows both how to plot lines and how to embed such plots in a bokeh plot in a Jupyter notebook. In a notebook, you just create a function that returns an image using datashader code, and then pass that to InteractiveImage, which requests an image for a given zoom level of the chosen Bokeh plot.

The dashboard example included with datashader shows how to embed datashader plots into standalone bokeh plots, rather than in a notebook, which works similarly but without using InteractiveImage. Hope that helps!

···

On Thu, Jun 23, 2016 at 2:03 PM, Trampas Stern [email protected] wrote:

I have watched the video and went through the examples on datashader but I still can not get it to work. I have not figured out how to link the datashader output to a bokeh figure.

Additionally I have not figured out how to get a datashader to plot a line instead of points.

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/CADqjcyhA5i-o534RoydBSTVgyidrY8nKayRLv3Muk%3DkkwSWnBQ%40mail.gmail.com.

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

Jim

On Thu, Jun 23, 2016 at 1:40 PM, Trampas Stern [email protected] wrote:

I am looking into datashader, but I am having trouble figuring out the canvas concept and how to use it in to my boken example.

thanks

Trampas

On Thu, Jun 23, 2016 at 9:11 AM, Bryan Van de Ven [email protected] wrote:

There is one thing that you are doing wrong, which is that you should really always update the .data attribute of a ColumnDataSource in a single operation, i.e., make a new dictionary up front, then set .data to that new dictionary, instead of updating keys individually:

    new_data = { # stuff }

    source.data = new_data

Doing it the way you are doing causes the server to update excessively, but also potentially violates the assumptions that all columns in a column data source are always the same length at all times.

Beyond that, sending hundreds of thousands of points to the browser is almost never going to be a good idea due to limitations of the browser. FOr larger data sets, you should look at the related bokeh/datashader library that has been used to interactively visualize hundreds of millions of points. A recent thread here has more information:

    [https://groups.google.com/a/continuum.io/forum/?pli=1#!topic/bokeh/o2x7CXpuB2w](https://groups.google.com/a/continuum.io/forum/?pli=1#!topic/bokeh/o2x7CXpuB2w)

Thanks,

Bryan

On Jun 23, 2016, at 8:02 AM, Trampas Stern [email protected] wrote:

I have the code below and find that bokeh is very slow to update the graphs, is there something I am doing wrong that would allow faster updates of the graphs?

import numpy as np

from numpy import pi

import bokeh

from bokeh.client import push_session

from bokeh.driving import cosine

from bokeh.plotting import Figure, curdoc

from bokeh.models.widgets import Select

from bokeh.models import ColumnDataSource, HBox, VBoxForm

from bokeh.models.widgets import Slider, TextInput, Toggle

import re

x = [0]

y = [0]

p = Figure()

#r1 = p.line([0, 4*pi], [-1, 1], color=“firebrick”)

r2 = p.line(x, y, color=“navy”, line_width=4)

p2=Figure()

r1=p2.line(x, y, color=“red”, line_width=4)

p3=Figure()

r3=p3.line(x, y, color=“red”, line_width=4)

r3a=p3.line(x, y, color=“blue”, line_width=2)

p2.x_range=p.x_range

p3.x_range=p.x_range

def ClearGraph():

r2.data_source.data["y"] = []
r2.data_source.data["x"] = []
r1.data_source.data["y"] = []
r1.data_source.data["x"] = []
r3.data_source.data["y"] = []
r3a.data_source.data["y"] = []
r3.data_source.data["x"] = []
r3a.data_source.data["x"] = []
p2.x_range=p.x_range
p3.x_range=p.x_range

def updateGraph():

N=200000;
p.title=""
print "Data Loaded"
x1=range(N)
y1=np.random.rand(N)
c1=np.random.rand(N)
t1=np.random.rand(N)
p1=np.random.rand(N)
print "Transform done"
r2.data_source.data["y"] = c1
r2.data_source.data["x"] = x1
print "graph1 done"
r1.data_source.data["y"] = y1
r1.data_source.data["x"] = x1
print "graph2 done"
r3.data_source.data["y"] = t1
r3a.data_source.data["y"] = p1
r3.data_source.data["x"] = x1
r3a.data_source.data["x"] = x1
print "graph3 done"

p2.x_range=p.x_range

p3.x_range=p.x_range

p.title="Done"
print len(x1)

def button_click(something):

#button.disabled=True
updateGraph()
#button.disabled=False
#print "button update"

button = Toggle(label=“Update Graph”, type=“success”)

button.on_click(button_click)

inputs = VBoxForm(children=[button])

x=VBoxForm(children=[p,p2,p3])

curdoc().add_root(HBox(children=[inputs,x], width=1000))

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(updateGraph, 30000)

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/CADqjcyjaAjd4skGWwD5oQQ9t_fwSjYMDNphjJgL50HLtMNKYBA%40mail.gmail.com.

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

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/998C435A-7908-4B61-B5C5-AE42E455BC47%40continuum.io.

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