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鈥檝e got so far and it sort of works but seems to stop updating after a period of time is as follows.
Please don鈥檛 judge me by my python, I鈥檓 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鈥檝e got so far and it sort of works but seems to stop updating after a period of time is as follows.
Please don鈥檛 judge me by my python, I鈥檓 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鈥檛 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鈥檝e got so far and it sort of works but seems to stop updating after a period of time is as follows.
Please don鈥檛 judge me by my python, I鈥檓 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 鈥淏okeh 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鈥檚 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鈥檛 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鈥檝e got so far and it sort of works but seems to stop updating after a period of time is as follows.

Please don鈥檛 judge me by my python, I鈥檓 new here :slight_smile:

output_server(鈥淭emperature鈥,url=鈥http://192.168.1.252:5006鈥)

p = figure(x_axis_type = 鈥渄atetime鈥,title=鈥淭emperature鈥,x_axis_label=鈥楾ime鈥,y_axis_label=鈥楾emp鈥)

p.line(x, y ,legend=鈥淭emperature鈥,name=鈥楾emperature鈥,color=鈥榬ed鈥)

p.line(x, y2 ,legend=鈥淭emperature2鈥,name=鈥楾emperature2鈥,color=鈥榖lue鈥)

show搂

renderer = p.select(dict(name=鈥淭emperature鈥))

ds = renderer[0].data_source

renderer2 = p.select(dict(name=鈥淭emperature2鈥))

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 鈥淏okeh 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 鈥淏okeh 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 鈥淏okeh 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.