python - 从 Bokeh 中的图形中删除线

标签 python user-interface bokeh

我是 Bokeh 的新手。我制作了一个小部件,当我单击一个复选框时,我希望能够在 Bokeh 图中添加/删除一行。我有 20 个这样的复选框,我不想重新绘制整个图形,只是在未选中复选框时删除 1 行。

这是通过回调完成的,我可以在回调中访问图形对象。我想有一种方法可以做这样的事情:

F=figure()
F.line('x', 'y', source=source, name='line1')
F.line('x', 'z', source=source, name='line2')

%%in callback
selected_line_name = 'line1' # this would be determined by checkbox
selected_line = F.children[selected_line_name]
delete(selected_line)

但是我不知道怎么办 1) 从其父对象访问一个字形 2) 删除一个字形

我尝试设置数据源 'y'=[],但由于所有列数据源的大小都必须相同,这会删除所有图...

最佳答案

有几种方式:

# Keep the glyphs in a variable:
line2 = F.line('x', 'z', source=source, name='line2')

# or get the glyph from the Figure:
line2 = F.select_one({'name': 'line2'})

# in callback:
line2.visible = False

关于python - 从 Bokeh 中的图形中删除线,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46480571/

相关文章:

python - 在 Django 中导入 python 模块 : __init__. py 类未加载

python - 关于程序的时间复杂度

python - 基于 `pytest` 和 `yield` 的测试

Python Traits UI (Enthought)

python - 使用 HoverTool 绘制 Bokeh 线图

python - 我可以将图中的代码更改为自定义文本代码吗?

python - 我们还应该为 ZipFile.open 捕获什么异常

java - JTextField 的 getText() 到可打印变量

xcode - macOS 10.10 中的 UI 布局问题(适用于 macOS 10.12)

python - Brewer.py 将 x 轴转换为日期