2

My Bokeh Streaming Plot is a blank rectangle. I am able to create a simple line plot that does not update itself in real-time. I have read the Bokeh documentation for the version of Bokeh I am using 0.12.10 and Python3.5.3. I have searched on-line extensively for a solution to the error message.

I am getting the error

Error thrown from periodic callback: ValueError('All streaming column updates must be the same length')

I am using pyserial to retrieve data from a sensor. The example values are 73.40 for temperature and 12:30:42 for the time. I want to plot this data in real-time.

Here is the code:

import serial
from bokeh.io import curdoc
from bokeh.models import ColumnDataSource
from bokeh.plotting import figure, output_file, show

ser = serial.Serial('/dev/ttyACM0', 9600)

source = ColumnDataSource(dict(time=[], sensor=[]))

p = figure(plot_height=400, plot_width=1200, title="Fahrenheit Plotting")

p.title.text = "Fahrenheit Plotter"
p.title.text_color = "blue"
p.title.text_font = "arial"
p.title.text_font_style = "bold"
p.yaxis.minor_tick_line_color = "yellow"
p.xaxis.axis_label = "Time"
p.yaxis.axis_label = "Fahrenheit"



p.line(x='time', y='sensor',line_width=3,color="blue",alpha=0.8,source=source)


def update():
    while True:
        arduinoString = ser.readline()
        data_array = str(arduinoString).split(',')
        time = data_array[1]
        sensor1 = data_array[2]
        print(sensor)
        print(time)
        new_data = dict(time=[], sensor1=[])
        new_data['time'] = data_array[1]
        new_data['sensor'] = data_array[2]
        source.stream(new_data, 20)

curdoc().add_root(p)
curdoc().add_periodic_callback(update, 100)
curdoc().title = "Device Temperatures"

1 Answer 1

1

The example code is not self-contained, so I can't run it to fix, and reply with an updated version. But the error message is telling you what is wrong. All columns in a ColumnDataSource data dictionary must always be the same length at all times. You new_data must look something analogous to this:

new_data = {
    'time'  : [1,2,3,4],
    'sensor : [100, 200] 
}

The columns for time and sensor (which happen the be lists here, but could be arrays, etc) do not have the same length. That is the problem. All columns of a CDS must always have the same length, at all times.

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you. I made the temperature string and the sensor string the same length like this: 00072:94 12:55:33. I do not get the error message anymore.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.