我有一个交互式 Bokeh 图,单击图例时可以隐藏某些圆形图。现在,当我通过单击来禁用绘图时,绘制的圆圈会消失,但注释仍然存在。有人可以向我解释一下如何将它们全部打开/关闭吗?或者有人有快速解决办法吗?
这是关闭时的图片:
我使用以下代码绘制圆圈+图例:
q.circle('lng', 'lat', source = source2, name='vri', color='red', size=5, hover_line_color="black", legend_label = 'VRI')
vri_labels = LabelSet(x='lng', y='lat', text='kruispuntn', x_offset=5, y_offset=5, source=source2, text_font_size = '10pt')
q.legend.location = "bottom_left"
q.legend.click_policy="hide"
q.add_layout(vri_labels)
show(q)
最佳答案
您可以通过 CustomJS
回调链接 visible
属性:
from bokeh.io import show
from bokeh.models import ColumnDataSource, LabelSet, CustomJS
from bokeh.plotting import figure
p = figure()
cds = ColumnDataSource(data=dict(x=[0, 1], y=[0, 1], z=[1, 0]))
for var, params in [('y', {}),
('z', {'color': 'green'})]:
renderer = p.circle('x', var, source=cds, legend_label=var, size=20, **params)
label_set = LabelSet(x='x', y=var, text=var, source=cds, x_offset=5, y_offset=5)
p.add_layout(label_set)
renderer.js_on_change('visible', CustomJS(args=dict(ls=label_set),
code="ls.visible = cb_obj.visible;"))
p.legend.click_policy = 'hide'
show(p)
关于python - 在 Bokeh 中隐藏图例旁边的注释,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61210735/