Multiple Live Streaming Data in a Single Figure

Good Day,

I am trying to plot multiple live streaming data points in a single bokeh plot but i’m not really sure how i should go about doing it.

I have managed to get two live stream data to be plotted simultaneously but i’m trying to get them into the same figure for comparison.

I would appreciate it if someone could point me in the right direction. Thanks! :slight_smile:

  • below is the snippet of what i have tried to do, two separate live plots.
# plot settings
plot_stream1 = figure(title="Test Stream 1")
plot_stream1.line(x, y, color="blue", name='Sample Streaming Data 1')

plot_stream2 = figure(title=“Test Stream 2”)
plot_stream2.line(x, y, color=“red”, name=‘Sample Streaming Data 2’)


# plot live streaming data
show(VBox(plot_stream1, plot_stream2))

# set up glyph renderer
ds1 = plot_stream1.select({"type": GlyphRenderer})[0].data_source
ds2 = plot_stream2.select({"type": GlyphRenderer})[0].data_source

while True:

counter += 1

    # get new data and time-stamp
    data = test_data[counter]
    time_point = time.time() - start_time

# update data into ds
ds1.data["x"].append(time_point)
ds1.data["y"].append(data)
ds2.data["x"].append(time_point)
    ds2.data["y"].append(data + 300)
# update live stream with new data
ds1._dirty = True
cursession().store_objects(ds1)

ds2._dirty = True
cursession().store_objects(ds2)

Put the lines on the same plot, and use the renderer name to query with select, so you can get the appropriate different data source for each:

  # plot settings
  plot = figure(title="Combined Streams")
  plot.line(x, y, color="blue", name='Sample Streaming Data 1')
  plot.line(x, y, color="red", name='Sample Streaming Data 2')

  show(plot)

  ds1 = plot.select({"name": 'Sample Streaming Data 1'})[0].data_source
  ds2 = plot.select({"name": 'Sample Streaming Data 2'})[0].data_source

Also note, you can do:

  cursession().store_objects(ds1, ds2)

in one call, and should not need to mark anything _dirty, either.

Bryan

···

On Aug 27, 2015, at 10:03 AM, Nathan Chew <[email protected]> wrote:

Good Day,

I am trying to plot multiple live streaming data points in a single bokeh plot but i'm not really sure how i should go about doing it.

I have managed to get two live stream data to be plotted simultaneously but i'm trying to get them into the same figure for comparison.

I would appreciate it if someone could point me in the right direction. Thanks! :slight_smile:

* below is the snippet of what i have tried to do, two separate live plots.

# plot settings
plot_stream1 = figure(title="Test Stream 1")
plot_stream1.line(x, y, color="blue", name='Sample Streaming Data 1')

plot_stream2 = figure(title="Test Stream 2")
plot_stream2.line(x, y, color="red", name='Sample Streaming Data 2')

# plot live streaming data
show(VBox(plot_stream1, plot_stream2))

# set up glyph renderer
ds1 = plot_stream1.select({"type": GlyphRenderer})[0].data_source
ds2 = plot_stream2.select({"type": GlyphRenderer})[0].data_source

while True:
    
    counter += 1

    # get new data and time-stamp
    data = test_data[counter]
    time_point = time.time() - start_time

    # update data into ds
    ds1.data["x"].append(time_point)
    ds1.data["y"].append(data)

    ds2.data["x"].append(time_point)
    ds2.data["y"].append(data + 300)

    # update live stream with new data
    ds1._dirty = True
    cursession().store_objects(ds1)

    ds2._dirty = True
    cursession().store_objects(ds2)

--
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/b05d7c4d-5b74-4d5b-9a4a-8215ecb012f5%40continuum.io.
For more options, visit https://groups.google.com/a/continuum.io/d/optout.

Hi Bryan,

Using your method, I have got the graph to plot multiple streaming lines in the same figure!

Many thanks for the help! Really appreciate it :slight_smile:

···

On Thursday, 27 August 2015 19:35:51 UTC+8, Bryan Van de ven wrote:

Put the lines on the same plot, and use the renderer name to query with select, so you can get the appropriate different data source for each:

    # plot settings

    plot = figure(title="Combined Streams")

    plot.line(x, y, color="blue", name='Sample Streaming Data 1')

    plot.line(x, y, color="red", name='Sample Streaming Data 2')



    show(plot)



    ds1 = plot.select({"name": 'Sample Streaming Data 1'})[0].data_source

    ds2 = plot.select({"name": 'Sample Streaming Data 2'})[0].data_source

Also note, you can do:

    cursession().store_objects(ds1, ds2)

in one call, and should not need to mark anything _dirty, either.

Bryan

On Aug 27, 2015, at 10:03 AM, Nathan Chew [email protected] wrote:

Good Day,

I am trying to plot multiple live streaming data points in a single bokeh plot but i’m not really sure how i should go about doing it.

I have managed to get two live stream data to be plotted simultaneously but i’m trying to get them into the same figure for comparison.

I would appreciate it if someone could point me in the right direction. Thanks! :slight_smile:

  • below is the snippet of what i have tried to do, two separate live plots.

plot settings

plot_stream1 = figure(title=“Test Stream 1”)

plot_stream1.line(x, y, color=“blue”, name=‘Sample Streaming Data 1’)

plot_stream2 = figure(title=“Test Stream 2”)

plot_stream2.line(x, y, color=“red”, name=‘Sample Streaming Data 2’)

plot live streaming data

show(VBox(plot_stream1, plot_stream2))

set up glyph renderer

ds1 = plot_stream1.select({“type”: GlyphRenderer})[0].data_source

ds2 = plot_stream2.select({“type”: GlyphRenderer})[0].data_source

while True:

counter += 1
# get new data and time-stamp
data = test_data[counter]
time_point = time.time() - start_time
# update data into ds
ds1.data["x"].append(time_point)
ds1.data["y"].append(data)
ds2.data["x"].append(time_point)
ds2.data["y"].append(data + 300)
# update live stream with new data
ds1._dirty = True
cursession().store_objects(ds1)
ds2._dirty = True
cursession().store_objects(ds2)


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/b05d7c4d-5b74-4d5b-9a4a-8215ecb012f5%40continuum.io.

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