博克不显示阴谋

2024-03-28 20:04:28 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在为bokeh图设计一个模板,它会定期更新以显示我正在读取的文件中的新数据。在

目前,我只是使用一个简单的生成器来生成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)

有什么想法吗?在


Tags: infromimportrightsourcefordatatop
1条回答
网友
1楼 · 发布于 2024-03-28 20:04:28

我测试过,除非您删除:

if __name__ == '__main__':

我猜bokeh的运行方式与标准程序不同。如果你去掉它,你就会开始出错,即

^{pr2}$

相关问题 更多 >