bokeh - 如何从 Bokeh 图中提取来源?

标签 bokeh

我将一个 Bokeh Figure 实例作为输入传递给另一个函数,我需要在那里修改它的源代码。
不知道该怎么做!

这就是我创建图形实例的方式:

source = ColumnDataSource({'x': [1,2,3], 'y': [2,4,6]})  

p = figure(tools='pan,wheel_zoom,save,reset', name='p', toolbar_location='above')  

p.circle('x', 'y', source=source, color='slategray', alpha=0.6, name='glyph')

获取这个数字的函数应该是这样的:

def modify_source(fig):
    fig.source.data['x'] = [6,7,8]
    return fig

最佳答案

data_source 是字形渲染器的一个属性:

circle = p.circle('x', 'y', source=source, color='slategray', alpha=0.6, name='glyph')
print(circle.data_source)

您传递给 ColumnDataSoource 的 JSON 数据可以通过以下方式访问:

print(circle.data_source.data)

一般对于给定的地 block :

plot = figure()
line = plot.line('x', 'y', source = source)
circle = plot.circle('x', 'y', source = source)
for renderer in plot.renderers:
    if hasattr(renderer, 'glyph'):
        print (renderer.data_source.data)

所以在你的情况下你可以这样做:

def modify_source(circle):
    circle.data_source.data['x'] = [6,7,8]
    circle.data_source.change.emit() # for changes to take effect
    return circle

关于bokeh - 如何从 Bokeh 图中提取来源?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56164328/

相关文章:

python - Bokeh 服务器白名单

python - Bokeh 0.12.14 + flask : Broken library or new syntax for AjaxDataSource?

python - 如何同时显示两个 Bokeh 对象?

python - Flask 应用程序中的 Bokeh 问题渲染图

python - 获取包含在 Bokeh 中的框选择工具中的选定数据

python - 将悬停工具与 vbar 字形结合使用

python - Bokeh :如何添加连接点的垂直线

html - Bokeh 服务器加载静态 CSS 样式表

datetime - 如何将 X 轴上的日期时间限制用于 Bokeh BoxAnnotation?

python - 使用 LinkedBrush gridplot 在 Bokeh 中绘制多个系列