2017-12-03 13 views
1

내 Bokeh 스트리밍 플롯은 빈 사각형입니다. 실시간으로 업데이트되지 않는 간단한 선 그림을 만들 수 있습니다. Bokeh 버전의 Bokeh 설명서를 읽었습니다. 0.12.10과 Python3.5.3을 사용하고 있습니다. 나는 온라인에서 오류 메시지에 대한 해결책을 광범위하게 검색했다.Bokeh 스트리밍 플롯이 비어 있음

나는 오류 내가 센서에서 데이터를 검색 pyserial를 사용하고

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

을 얻고있다. 예제 값은 온도가 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" 

답변

1

, 그래서 수정을 실행하고 업데이트 된 버전으로 회신 할 수 없습니다. 그러나 오류 메시지는 무엇이 잘못되었는지 알려줍니다. ColumnDataSource 데이터 사전의 모든 열은 항상 항상 같은 길이 여야합니다. 같은 길이가없는 timesensor에 대한

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

열을 (여기 일 목록을 발생하지만, 등을 배열 될 수있다) : 당신은 new_data이 유사 보일해야합니다. 그게 문제 야. CDS의 모든 열은 항상 동일한 길이 여야합니다.

+0

감사합니다. 나는 온도 줄과 센서 줄을 같은 길이로 만들었습니다 :'00072 : 94''12 : 55 : 33'. 더 이상 오류 메시지가 표시되지 않습니다. – tluafed