我正在尝试根据发布的简单示例代码在Bokeh中绘制散点图。
here
.
以下代码为线图生成一个工作演示:
from bokeh.layouts import column
from bokeh.models import CustomJS, ColumnDataSource, Slider
from bokeh.plotting import Figure, show
# fetch and clear the document
from bokeh.io import curdoc
curdoc().clear()
x = [x*0.005 for x in range(0, 100)]
y = x
source = ColumnDataSource(data=dict(x=x, y=y))
plot = Figure(plot_width=400, plot_height=400)
plot.line(x='x', y='y', source=source)
def callback(source=source, window=None):
data = source.data
f = cb_obj.value
x, y = data['x'], data['y']
for i in range(len(x)):
y[i] = window.Math.pow(x[i], f)
source.trigger('change')
slider = Slider(start=0.1, end=4, value=1, step=.1, title="Start week",
callback=CustomJS.from_py_func(callback))
layout = column(slider, plot)
show(layout)
看起来是这样的:
在本演示中,当您调整滑块并按下“重置”图标时,绘图将根据更新的y=f(x)公式重新绘制自身。
但是,我想制作一个变化的散点图,而不是一个折线图。
问题:
当我简单的改变
plot.line
在上述代码中
plot.circle
,绘图显示正常,但它是静态的-当您移动滑块并按“重置”时,它不会改变。我看不到错误消息。