【问题标题】:Hide annotation alongside legend in Bokeh在散景中隐藏注释旁边的图例
【发布时间】:2020-07-27 08:39:16
【问题描述】:

我有一个交互式散景图,可以在单击图例时隐藏某些圆形图。现在,当我通过单击禁用绘图时,绘制的圆圈会消失,但注释仍然存在。有人可以向我解释如何将它们全部打开/关闭,或者有人有快速修复吗?

这是关闭时的图片:

我用以下代码绘制圆圈+图例:

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)

【问题讨论】:

    标签: python pandas plot bokeh


    【解决方案1】:

    您可以通过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)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-08-13
      • 1970-01-01
      • 1970-01-01
      • 2012-03-04
      • 1970-01-01
      • 2014-07-26
      • 2018-08-04
      相关资源
      最近更新 更多