2017-02-07 8 views
1

ボケストリーミング問題:私は次のコードを持ってラインシフト

import random 
import datetime as dt 

from bokeh.models import ColumnDataSource 
from bokeh.plotting import curdoc, figure 


source = ColumnDataSource(dict(
    x = [], y = [] 
)) 

p = figure(plot_height=250, plot_width=400, tools="save", 
      x_axis_type="datetime", y_axis_location="right") 
p.x_range.follow = "end" 
p.x_range.follow_interval = 5000 # ms 
p.line(x='x', y='y', color='red', source=source) 

cur_time = dt.datetime.now() 
step = dt.timedelta(seconds=1) 

def update(): 
    global cur_time, step 
    new_data = dict(x=[], y=[]) 
    new_data['x'].append(cur_time) 
    new_data['y'].append(random.randint(1, 100)) 
    cur_time += step 
    source.stream(new_data, 60) # how many data are saved 

curdoc().add_root(p) 
curdoc().add_periodic_callback(update, 500) 

は、私がデータをカットしたかったので、私はstream methodにロールオーバーパラメータを追加しました。

enter image description here

しかし、後にラインがシフトし始めている間:最初はそれはOKだ

enter image description here

なぜそれがそのように動作しますか?そしてこれを修正する方法は?

ありがとうございました!

答えて

0
import random 
import datetime as dt 

from bokeh.models import ColumnDataSource 
from bokeh.plotting import curdoc, figure 


source = ColumnDataSource(dict(
    x = [], y = [] 
)) 

p = figure(plot_height=250, plot_width=400, tools="save", 
      x_axis_type="datetime", y_axis_location="right") 
# p.x_range.follow = "end" #***** THIS IS YOUR ISSUE ***** 
p.x_range.follow_interval = 500 # ms 
p.line(x='x', y='y', color='red', source=source) 

cur_time = dt.datetime.now() 
step = dt.timedelta(seconds=1) 

def update(): 
    global cur_time, step 
    new_data = dict(x=[], y=[]) 
    new_data['x'].append(cur_time) 
    new_data['y'].append(random.randint(1, 100)) 
    cur_time += step 
    source.stream(new_data, 60) # how many data are saved 

curdoc().add_root(p) 
curdoc().add_periodic_callback(update, 50) 

私の編集を参照してください。 x_range.followは必要ありません。http://bokeh.pydata.org/en/0.11.1/docs/reference/models/ranges.html

関連する問題