如何将以下流式图嵌入烧瓶应用程序中?
from bokeh.io import curdoc
from bokeh.models import ColumnDataSource
from bokeh.plotting import Figure
import numpy as np
source = ColumnDataSource(dict(x=[], y=[], avg=[]))
fig = Figure()
fig.line(source=source, x='x', y='y', line_width=2, alpha=0.85, color='red')
fig.line(source=source, x='x', y='avg', line_width=2, alpha=0.85, color='blue')
ct = 0
sine_sum = 0
def update_data():
global ct, sine_sum
ct += 1
sine = np.sin(ct)
sine_sum += sine
new_data = dict(x=[ct], y=[sine], avg=[sine_sum / ct])
print(new_data)
source.stream(new_data, 100)
curdoc().add_root(fig)
curdoc().add_periodic_callback(update_data, 500)
在bokeh.embed api更改之后,我找不到这样的例子。