动态定期更新python散景

时间:2016-10-03 10:33:24

标签: python dynamic charts stream bokeh

我有以下散景代码如何动态地向图表添加水平线或字形我需要回调吗?

在文档http://bokeh.pydata.org/en/latest/docs/user_guide/interaction/callbacks.html中,它说"可以使用CustomJS对象设置像这样的自定义回调,并将其作为回调参数传递给Widget对象。"

所以我在更新之前或之后设置回电...

source = ColumnDataSource(dict(
    time=[], average=[], low=[], high=[], open=[], close=[],
    ma=[], macd=[], macd9=[], macdh=[], color=[]
))

#main chart
p = figure(plot_height=500, tools="xpan,xwheel_zoom,xbox_zoom,reset,crosshair,hover", x_axis_type=None, y_axis_location="right")
p.x_range.follow = "end"
p.x_range.follow_interval = 100
p.x_range.range_padding = 0
p.axis.minor_tick_in = -2
p.axis.minor_tick_out = 5

p.segment(x0='time', y0='low', x1='time', y1='high', line_width=2, color='black', source=source)
p.segment(x0='time', y0='open', x1='time', y1='close', line_width=8, color='color', source=source)

...
@count()
def update(t):
    open, high, low, close, average = _get_prices(t)
    color = "green" if open < close else "red"

    new_data = dict(
        time=[t],
        open=[open],
        high=[high],
        low=[low],
        close=[close],
        color=[color],
    )
    print(open)
    source.stream(new_data, 300)

output_notebook()
curdoc().add_periodic_callback(update, 50)
curdoc().title = "OHLC"

0 个答案:

没有答案