Multiple traces per plot updating dynamically ?

Hi everyone,
Does anyone have any python code showing how to plot multiple dyamic traces per plot.
Are multiple datasources and renderers the way to go ?

What I’ve got so far and it sort of works but seems to stop updating after a period of time is as follows.
Please don’t judge me by my python, I’m new here :slight_smile:

output_server("Temperature",url="http://192.168.1.252:5006")
p = figure(x_axis_type = "datetime",title="Temperature",x_axis_label='Time',y_axis_label='Temp')
p.line(x, y ,legend="Temperature",name='Temperature',color='red')
p.line(x, y2 ,legend="Temperature2",name='Temperature2',color='blue')
show(p)

renderer = p.select(dict(name="Temperature"))
ds = renderer[0].data_source

renderer2 = p.select(dict(name="Temperature2"))
ds2 = renderer2[0].data_source
print ds2.data

ser = serial.Serial('/dev/ttyUSB0', 57600)

while 1:
    if update_count==0:
        run_start_time=datetime.datetime.now()

    line = ser.readline()  # read a '\n' terminated line
    csvdata = line.split(',')
    print csvdata
    if len(csvdata) == 6 and not(csvdata[0]=='4'):
       
        x = datetime.datetime.now()
       
        light[csvdata[0]] =[x,int(csvdata[1])]
        temperature[csvdata[0]] =[x,float(csvdata[2])]
        humidity[csvdata[0]] = [x,float(csvdata[3])]
        gas[csvdata[0]] = [x,int(csvdata[4])]
        pressure[csvdata[0]] = [x,float(csvdata[5])]
        update_count+=1
    run_current_time=datetime.datetime.now()
    run_elapsed_time=run_current_time-run_start_time

    if update_count%4==0:
        print 'Doing plot'
        if '1' in temperature:
            ds.data["x"].append(temperature['1'][0])
            ds.data["y"].append(temperature['1'][1])
            cursession().store_objects(ds)

        if '2' in temperature:
            ds2.data["x"].append(temperature['2'][0])
            ds2.data["y"].append(temperature['2'][1])
            cursession().store_objects(ds2)
Enter code here...

``

Thanks
Lachlan

You are maybe interested in this thread I opened some time ago:

https://groups.google.com/a/continuum.io/d/msg/bokeh/8i01xwr1t0c/oHfUDZ7XmWwJ

(Also having some synthetic example that does not need a physical device plugged helps a lot so someone else is able to execute it).

Good luck!

···

El lunes, 9 de febrero de 2015, 0:07:16 (UTC+1), Lachlan Kidd escribió:

Hi everyone,
Does anyone have any python code showing how to plot multiple dyamic traces per plot.
Are multiple datasources and renderers the way to go ?

What I’ve got so far and it sort of works but seems to stop updating after a period of time is as follows.
Please don’t judge me by my python, I’m new here :slight_smile:

output_server("Temperature",url="[http://192.168.1.252:5006](http://192.168.1.252:5006)")
p = figure(x_axis_type = "datetime",title="Temperature",x_axis_label='Time',y_axis_label='Temp')
p.line(x, y ,legend="Temperature",name='Temperature',color='red')
p.line(x, y2 ,legend="Temperature2",name='Temperature2',color='blue')
show(p)

renderer = p.select(dict(name="Temperature"))
ds = renderer[0].data_source

renderer2 = p.select(dict(name="Temperature2"))
ds2 = renderer2[0].data_source
print ds2.data

ser = serial.Serial('/dev/ttyUSB0', 57600)

while 1:
    if update_count==0:
        run_start_time=datetime.datetime.now()

    line = ser.readline()  # read a '\n' terminated line
    csvdata = line.split(',')
    print csvdata
    if len(csvdata) == 6 and not(csvdata[0]=='4'):
       
        x = datetime.datetime.now()
       
        light[csvdata[0]] =[x,int(csvdata[1])]
        temperature[csvdata[0]] =[x,float(csvdata[2])]
        humidity[csvdata[0]] = [x,float(csvdata[3])]
        gas[csvdata[0]] = [x,int(csvdata[4])]
        pressure[csvdata[0]] = [x,float(csvdata[5])]
        update_count+=1
    run_current_time=datetime.datetime.now()
    run_elapsed_time=run_current_time-run_start_time

    if update_count%4==0:
        print 'Doing plot'
        if '1' in temperature:
            ds.data["x"].append(temperature['1'][0])
            ds.data["y"].append(temperature['1'][1])
            cursession().store_objects(ds)

        if '2' in temperature:
            ds2.data["x"].append(temperature['2'][0])
            ds2.data["y"].append(temperature['2'][1])
            cursession().store_objects(ds2)
Enter code here...

``

Thanks
Lachlan

Thanks, yes I saw your post and based my attempt on it.

Good point on the physical device, be meaning to do that.

So, did you manage to improve the performance for your use case ?

I wonder if moving away from streaming and just regenerating my plots every minute might be a better approach. I don’t need anything like the speed that your data was coming in.

···

On Tue, Feb 10, 2015 at 1:21 AM, Sam Pfeiffer [email protected] wrote:

You are maybe interested in this thread I opened some time ago:

https://groups.google.com/a/continuum.io/d/msg/bokeh/8i01xwr1t0c/oHfUDZ7XmWwJ

(Also having some synthetic example that does not need a physical device plugged helps a lot so someone else is able to execute it).

Good luck!

El lunes, 9 de febrero de 2015, 0:07:16 (UTC+1), Lachlan Kidd escribió:

Hi everyone,
Does anyone have any python code showing how to plot multiple dyamic traces per plot.
Are multiple datasources and renderers the way to go ?

What I’ve got so far and it sort of works but seems to stop updating after a period of time is as follows.
Please don’t judge me by my python, I’m new here :slight_smile:

output_server("Temperature",url="[http://192.168.1.252:5006](http://192.168.1.252:5006)")
p = figure(x_axis_type = "datetime",title="Temperature",x_axis_label='Time',y_axis_label='Temp')
p.line(x, y ,legend="Temperature",name='Temperature',color='red')
p.line(x, y2 ,legend="Temperature2",name='Temperature2',color='blue')
show(p)

renderer = p.select(dict(name="Temperature"))
ds = renderer[0].data_source

renderer2 = p.select(dict(name="Temperature2"))
ds2 = renderer2[0].data_source
print ds2.data

ser = serial.Serial('/dev/ttyUSB0', 57600)

while 1:
    if update_count==0:
        run_start_time=datetime.datetime.now()

    line = ser.readline()  # read a '\n' terminated line
    csvdata = line.split(',')
    print csvdata
    if len(csvdata) == 6 and not(csvdata[0]=='4'):
       
        x = datetime.datetime.now()
       
        light[csvdata[0]] =[x,int(csvdata[1])]
        temperature[csvdata[0]] =[x,float(csvdata[2])]
        humidity[csvdata[0]] = [x,float(csvdata[3])]
        gas[csvdata[0]] = [x,int(csvdata[4])]
        pressure[csvdata[0]] = [x,float(csvdata[5])]
        update_count+=1
    run_current_time=datetime.datetime.now()
    run_elapsed_time=run_current_time-run_start_time

    if update_count%4==0:
        print 'Doing plot'
        if '1' in temperature:
            ds.data["x"].append(temperature['1'][0])
            ds.data["y"].append(temperature['1'][1])
            cursession().store_objects(ds)

        if '2' in temperature:
            ds2.data["x"].append(temperature['2'][0])
            ds2.data["y"].append(temperature['2'][1])
            cursession().store_objects(ds2)
Enter code here...

``

Thanks
Lachlan

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/4c968326-7167-429e-968c-ecfbfb552701%40continuum.io.

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

One thing to suggest to both of you for now, is to batch your updates to the server. So instead of pushing one data source at a time, push all of them at once, if possible. We are looking into this, and also new planned features like server data sources and incremental/streaming updates should help as well when they land.

Thanks,

Bryan

···

On Feb 9, 2015, at 4:11 PM, Lachlan Kidd <[email protected]> wrote:

Thanks, yes I saw your post and based my attempt on it.
Good point on the physical device, be meaning to do that.
So, did you manage to improve the performance for your use case ?
I wonder if moving away from streaming and just regenerating my plots every minute might be a better approach. I don't need anything like the speed that your data was coming in.

On Tue, Feb 10, 2015 at 1:21 AM, Sam Pfeiffer <[email protected]> wrote:
You are maybe interested in this thread I opened some time ago:

https://groups.google.com/a/continuum.io/d/msg/bokeh/8i01xwr1t0c/oHfUDZ7XmWwJ

(Also having some synthetic example that does not need a physical device plugged helps a lot so someone else is able to execute it).

Good luck!

El lunes, 9 de febrero de 2015, 0:07:16 (UTC+1), Lachlan Kidd escribió:
Hi everyone,
Does anyone have any python code showing how to plot multiple dyamic traces per plot.
Are multiple datasources and renderers the way to go ?

What I've got so far and it sort of works but seems to stop updating after a period of time is as follows.
Please don't judge me by my python, I'm new here :slight_smile:
output_server("Temperature",url="http://192.168.1.252:5006")
p = figure(x_axis_type = "datetime",title="Temperature",x_axis_label='Time',y_axis_label='Temp')
p.line(x, y ,legend="Temperature",name='Temperature',color='red')
p.line(x, y2 ,legend="Temperature2",name='Temperature2',color='blue')
show(p)

renderer = p.select(dict(name="Temperature"))
ds = renderer[0].data_source

renderer2 = p.select(dict(name="Temperature2"))
ds2 = renderer2[0].data_source
print ds2.data

ser = serial.Serial('/dev/ttyUSB0', 57600)

while 1:
    if update_count==0:
        run_start_time=datetime.datetime.now()

    line = ser.readline() # read a '\n' terminated line
    csvdata = line.split(',')
    print csvdata
    if len(csvdata) == 6 and not(csvdata[0]=='4'):
        
        x = datetime.datetime.now()
        
        light[csvdata[0]] =[x,int(csvdata[1])]
        temperature[csvdata[0]] =[x,float(csvdata[2])]
        humidity[csvdata[0]] = [x,float(csvdata[3])]
        gas[csvdata[0]] = [x,int(csvdata[4])]
        pressure[csvdata[0]] = [x,float(csvdata[5])]
        update_count+=1
    run_current_time=datetime.datetime.now()
    run_elapsed_time=run_current_time-run_start_time

    if update_count%4==0:
        print 'Doing plot'
        if '1' in temperature:
            ds.data["x"].append(temperature['1'][0])
            ds.data["y"].append(temperature['1'][1])
            cursession().store_objects(ds)

        if '2' in temperature:
            ds2.data["x"].append(temperature['2'][0])
            ds2.data["y"].append(temperature['2'][1])
            cursession().store_objects(ds2)
Enter code here...

Thanks
Lachlan

--
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/4c968326-7167-429e-968c-ecfbfb552701%40continuum.io\.

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/CAFnKoMfDOy4Mw%3D044zWYtTNipz4L1R-EfM%2B%2B4ZZ1tjGSaozmLw%40mail.gmail.com\.
For more options, visit https://groups.google.com/a/continuum.io/d/optout\.

thanks Bryan, so from a code perspective, what would this look like ? it’s it multiple ds objects ? do you need to

cursession().store_objects(ds1)
cursession().store_objects(ds2)
cursession().store_objects(ds3)

or can I send a list of ds to store_objects ?

Are there any docs on how to use the renderer[0].data_source ? I find the reference guide (and I'm a noob, so it could be me) confusing at best.



···

On Tue, Feb 10, 2015 at 9:16 AM, Bryan Van de Ven [email protected] wrote:

One thing to suggest to both of you for now, is to batch your updates to the server. So instead of pushing one data source at a time, push all of them at once, if possible. We are looking into this, and also new planned features like server data sources and incremental/streaming updates should help as well when they land.

Thanks,

Bryan

On Feb 9, 2015, at 4:11 PM, Lachlan Kidd [email protected] wrote:

Thanks, yes I saw your post and based my attempt on it.

Good point on the physical device, be meaning to do that.

So, did you manage to improve the performance for your use case ?

I wonder if moving away from streaming and just regenerating my plots every minute might be a better approach. I don’t need anything like the speed that your data was coming in.

On Tue, Feb 10, 2015 at 1:21 AM, Sam Pfeiffer [email protected] wrote:

You are maybe interested in this thread I opened some time ago:

https://groups.google.com/a/continuum.io/d/msg/bokeh/8i01xwr1t0c/oHfUDZ7XmWwJ

(Also having some synthetic example that does not need a physical device plugged helps a lot so someone else is able to execute it).

Good luck!

El lunes, 9 de febrero de 2015, 0:07:16 (UTC+1), Lachlan Kidd escribió:

Hi everyone,

Does anyone have any python code showing how to plot multiple dyamic traces per plot.

Are multiple datasources and renderers the way to go ?

What I’ve got so far and it sort of works but seems to stop updating after a period of time is as follows.

Please don’t judge me by my python, I’m new here :slight_smile:

output_server(“Temperature”,url=“http://192.168.1.252:5006”)

p = figure(x_axis_type = “datetime”,title=“Temperature”,x_axis_label=‘Time’,y_axis_label=‘Temp’)

p.line(x, y ,legend=“Temperature”,name=‘Temperature’,color=‘red’)

p.line(x, y2 ,legend=“Temperature2”,name=‘Temperature2’,color=‘blue’)

show(p)

renderer = p.select(dict(name=“Temperature”))

ds = renderer[0].data_source

renderer2 = p.select(dict(name=“Temperature2”))

ds2 = renderer2[0].data_source

print ds2.data

ser = serial.Serial(‘/dev/ttyUSB0’, 57600)

while 1:

if update_count==0:
    run_start_time=datetime.datetime.now()
line = ser.readline()  # read a '\n' terminated line
csvdata = line.split(',')
print csvdata
if len(csvdata) == 6 and not(csvdata[0]=='4'):
    x = datetime.datetime.now()
    light[csvdata[0]] =[x,int(csvdata[1])]
    temperature[csvdata[0]] =[x,float(csvdata[2])]
    humidity[csvdata[0]] = [x,float(csvdata[3])]
    gas[csvdata[0]] = [x,int(csvdata[4])]
    pressure[csvdata[0]] = [x,float(csvdata[5])]
    update_count+=1
run_current_time=datetime.datetime.now()
run_elapsed_time=run_current_time-run_start_time
if update_count%4==0:
    print 'Doing plot'
    if '1' in temperature:
        ds.data["x"].append(temperature['1'][0])
        ds.data["y"].append(temperature['1'][1])
        cursession().store_objects(ds)
    if '2' in temperature:
        ds2.data["x"].append(temperature['2'][0])
        ds2.data["y"].append(temperature['2'][1])
        cursession().store_objects(ds2)

Enter code here…

Thanks

Lachlan

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/4c968326-7167-429e-968c-ecfbfb552701%40continuum.io.

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/CAFnKoMfDOy4Mw%3D044zWYtTNipz4L1R-EfM%2B%2B4ZZ1tjGSaozmLw%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/10295470-DE31-423E-BF2B-1705296429D8%40continuum.io.
For more options, visit https://groups.google.com/a/continuum.io/d/optout.