2017-02-13 80 views
0

我正在为散景图设计模板,该模板会定期更新以显示我正在阅读的文件中的新数据。未显示阴谋的散景

目前,我只是使用一个简单的发生器,使numpy阵列只是为了测试应用程序。

但是,当我执行bokeh serve --show test.py时,浏览器中没有显示任何内容。我不知道如何继续,因为没有错误。我尝试使用print语句进行调试显示回调函数没有工作。

这个特殊的测试应该在每次更新时在同一个图上创建多个直方图。

import numpy as np 
from bokeh.io import curdoc 
from bokeh.models import ColumnDataSource 
from bokeh.plotting import figure 

def histplot_updater(sources, data_stream): 
    def updater(): 
     data = data_stream.next() 
     print 'got data' 
     for i in range(data.shape[1]): 
      d = data[:, i] 
      mind = np.min(d) 
      maxd = np.max(d) 
      step = max((maxd - mind) // 100, 1) 
      hist, edges = np.histogram(d, density=True, bins=range(mind, maxd + 2, step)) 
      new_data = {'top': hist, 'left': edges[:-1], 'right': edges[1:]} 
      sources[i].data = new_data 
    return updater 

def init_histplot(f, data, **kwargs): 
    hs = [] 
    ss = [] 
    for i in range(data.shape[1]): 
     source = ColumnDataSource(dict(top=[], left=[], right=[])) 
     kwgs = {k: v[i] for k,v in kwargs.items()} 
     h = f.quad(top='top', bottom=0, left='left', right='right', source=source, **kwgs) 
     hs.append(h) 
     ss.append(source) 
    return hs, ss 

if __name__ == '__main__': 
    fig = figure() 
    Data = (np.random.normal([0, 1], [1, 2], (1000, 2)) for i in xrange(100)) 

    h_sources = init_histplot(fig, Data)[1] 
    curdoc().add_root(fig) 
    curdoc().add_periodic_callback(histplot_updater(h_sources), 1000) 

任何想法?

回答

0

我测试,没有你的代码的执行,除非你删除:

if __name__ == '__main__': 

我猜的背景虚化不运行方式与标准程序相同。如果你删除,那么你开始得到错误,即

Error running application handler <bokeh.application.handlers.script.ScriptHandler object at 0x7fed2cc1a590>: 'generator' object has no attribute 'shape' 
+0

好,现在我可以开始调试。有关它为什么会如此工作的任何想法? – Lucidnonsense

+0

我不确定,我最好的猜测是,主要是在散景方面,然后它调用我们的代码,所以我们不在技术上写主 – bourneeoo