如何将元素添加到现有Bokeh ch

2024-09-30 18:19:03 发布

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

我试图做一个简单的实时股票数据可视化使用博凯。我已经创建了对象数据类型Candle,它具有属性timehighestlowestopenclosecandle1candle2candle3Candle的实例。我使用下面的代码显示一个包含这3个实例数据的图。如果我想在显示完图表(调用show(plot))后添加第四个蜡烛,我应该怎么做?我认为我没有做到这一点,因为html包含静态数据,但我不知道如何做我想做的事情。你知道吗

目标是每分钟收到一支蜡烛,并将其添加到图表中。你知道吗

plot = figure(x_axis_type="datetime", width = 1000, height= 300, title ="Live Chart", sizing_mode  ='scale_both')
plot.segment(candle1.time, candle1.highest, candle1.time, candle1.lowest, color="black")
plot.segment(candle2.time, candle2.highest, candle2.time, candle2.lowest, color="black")

plot.vbar(candle1.time, 0.5 *60*60*1000, candle1.open, candle1.close,fill_color="#00ff80", line_color="black")
plot.vbar(candle2.time, 0.5 * 60 * 60 * 1000, candle2.open, candle2.close, fill_color="#00ff80",
          line_color="black")
output_file("candlestick.html", title="Candle example")
show(plot)

Tags: 数据实例closetimeplotshow图表open
1条回答
网友
1楼 · 发布于 2024-09-30 18:19:03

只是一个更新:我使用一个ColumnDataSource、stream函数和一个自动回调实现了这一点。你知道吗

def update():
     candle_data.stream(new_data, 300)   

plot = figure(x_axis_type='datetime',x_range=(start_day, final_day), width=1500, height=900, title='Live Chart', sizing_mode='scale_both')
    plot.segment(x0='time', y0='highest', x1='time', y1='lowest', color='black', source=candle_data)
    plot.vbar(x='time', width = 0.5*60*60*50 ,bottom='open', top='close',fill_color='color', line_color='black', source = candle_data) doc.add_root(column([plot]))
doc.add_periodic_callback(update, 20000)
doc.title = "Candle Data Live Rates"

相关问题 更多 >