【问题标题】:Can I draw an annotation in bokeh with data from a ColumnDataSource?我可以使用来自 ColumnDataSource 的数据在散景中绘制注释吗?
【发布时间】:2018-01-16 18:59:19
【问题描述】:

我想在我的散景图上画一条垂直线,它在运行时由浏览器中的 javascript 移动。 (它是在时间序列图上标记当前时间的时间条。)

为了绘制静态垂直线,我使用的是:

from bokeh.models import Span
timebar = Span(location=where_I_want_the_timebar, dimension=height)
my_figure.add_layout(timebar)

为了启用交互性,我想我需要从ColumnDataSource 获取location。但是,我不知道该怎么做,因为Span 不接受source 参数。

或者,我还有其他方法可以在运行时移动时间栏吗?

【问题讨论】:

    标签: bokeh timeserieschart


    【解决方案1】:

    我找到了解决方法。在python中:

    from bokeh.models import Span
    timebar = Span(name='timebar' location=where_I_want_the_timebar, dimension=height)
    my_figure.add_layout(timebar)
    

    然后在浏览器的javascript中:

    let timebar = Bokeh.documents[0].get_model_by_name('timebar')
    timebar.attributes.location = my_new_desired_location
    timebar.change.emit()
    

    如果有人发布了使用 ColumnDataSource 的方法,我会接受该答案。

    【讨论】:

      猜你喜欢
      • 2016-08-11
      • 2015-12-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-02-02
      相关资源
      最近更新 更多