【问题标题】:Bokeh not showing plots散景不显示情节
【发布时间】:2017-02-16 17:44:05
【问题描述】:

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

目前,我只是使用一个简单的生成器来生成 numpy 数组来测试应用程序。

但是,当我执行bokeh serve --show test.py 时,浏览器中没有任何显示。我不确定如何继续,因为没有错误。我尝试使用打印语句进行调试表明回调甚至不起作用。

这个特定的测试应该在每次更新时在同一个图上制作多个直方图。

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)

有什么想法吗?

【问题讨论】:

    标签: python bokeh


    【解决方案1】:

    我测试过,除非您删除,否则您的任何代码都不会执行:

    if __name__ == '__main__':
    

    我猜散景与标准程序的运行方式不同。如果您删除它,那么您将开始收到错误,即

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

    【讨论】:

    • 太好了,现在我可以开始调试了。关于它为什么会这样工作的任何想法?
    • 我不确定,我最好的猜测是 main 在 bokeh 方面,然后它调用我们的代码,所以我们在技术上不是在编写 main
    猜你喜欢
    • 2018-03-14
    • 1970-01-01
    • 2021-10-20
    • 1970-01-01
    • 1970-01-01
    • 2019-08-31
    • 1970-01-01
    • 2014-09-13
    • 1970-01-01
    相关资源
    最近更新 更多