散景流图为空白
Bokeh Streaming Plot is Blank
我的 Bokeh Streaming Plot 是一个空白矩形。我能够创建一个不会实时更新的简单线图。
我已经阅读了我使用的 Bokeh 版本的 Bokeh 文档 0.12.10 和 Python3.5.3。我在网上广泛搜索了错误消息的解决方案。
我遇到错误
Error thrown from periodic callback: ValueError('All streaming column updates must be the same length')
我正在使用 pyserial 从传感器检索数据。温度的示例值为 73.40,时间的示例值为 12:30:42。我想实时绘制这些数据。
代码如下:
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"
示例代码不是独立的,所以我无法 运行 修复它,并用更新的版本回复。但是错误消息告诉你出了什么问题。 ColumnDataSource
数据字典中的所有列必须始终具有相同的长度。你 new_data
看起来一定与此类似:
new_data = {
'time' : [1,2,3,4],
'sensor : [100, 200]
}
time
和 sensor
的列(恰好是此处的列表,但也可能是数组等)的长度不同。那就是问题所在。 CDS 的所有列必须始终具有相同的长度。
我的 Bokeh Streaming Plot 是一个空白矩形。我能够创建一个不会实时更新的简单线图。 我已经阅读了我使用的 Bokeh 版本的 Bokeh 文档 0.12.10 和 Python3.5.3。我在网上广泛搜索了错误消息的解决方案。
我遇到错误
Error thrown from periodic callback: ValueError('All streaming column updates must be the same length')
我正在使用 pyserial 从传感器检索数据。温度的示例值为 73.40,时间的示例值为 12:30:42。我想实时绘制这些数据。
代码如下:
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"
示例代码不是独立的,所以我无法 运行 修复它,并用更新的版本回复。但是错误消息告诉你出了什么问题。 ColumnDataSource
数据字典中的所有列必须始终具有相同的长度。你 new_data
看起来一定与此类似:
new_data = {
'time' : [1,2,3,4],
'sensor : [100, 200]
}
time
和 sensor
的列(恰好是此处的列表,但也可能是数组等)的长度不同。那就是问题所在。 CDS 的所有列必须始终具有相同的长度。