简体   繁体   English

如何使用 ColumnDataSource 更新 Span (Bokeh)?

[英]How to update Span (Bokeh) using ColumnDataSource?

I am trying to update Span using ColumnDataSource, but the information is not being passed onto the source.我正在尝试使用 ColumnDataSource 更新 Span,但信息未传递到源。 Span unfortunately does not have a paremeter "source", so is there a better way?不幸的是,Span 没有参数“来源”,那么有更好的方法吗?

I have defined my sources, figure and line like so:我已经定义了我的来源、图形和线条,如下所示:

m1_source = ColumnDataSource(data=dict(x1=[], y1=[]))
m1_spans = ColumnDataSource(data=dict(x1=[]))    
p = figure(x_axis_type="datetime", title="", sizing_mode="fixed", height = 500, width = 1400)
p.line(x ="x1", y="y1", color = 'blue', source=m1_source)

Then I have a for loop that should ideally plot multiple spans, each 'i' will be a separate timestamp:然后我有一个 for 循环,理想情况下应该是 plot 多个跨度,每个“i”将是一个单独的时间戳:

for i in m1_spans.data['x1']:
    p.add_layout(Span(location=i, dimension='height', line_color='red', line_dash='solid', line_width=1))

This is taken from my update() function:这取自我的 update() function:

m1_source.data = dict(
   x1=machine_1_vals['mpTimestamp'],
   y1=machine_1_vals['Value'])

m1_spans.data = dict( x1=ToolsDF.loc[ToolsDF['Value'] == float(vals['Tool_val'])]['Timestamp'])

I have checked this, and m1_spans does successfully return multiple timestamps, so the error shouldn't be here.我已经检查过了,m1_spans 确实成功返回了多个时间戳,所以错误不应该在这里。

The reason I am confused, is because my p.line will successfully update with no issues, but it does have a source parameter, while span does not.我感到困惑的原因是因为我的 p.line 将成功更新而没有问题,但它确实有一个source参数,而 span 没有。

I would be really appreciative for any advice about how to solve this issue.对于如何解决此问题的任何建议,我将不胜感激。 If I should have supplied more information, I apologize and can update as needed, I just tried to keep it brief for you.如果我应该提供更多信息,我深表歉意,并且可以根据需要进行更新,我只是试图为您保持简短。

Thanks.谢谢。

Span objects do not currently have an ability to be "powered" by a ColumnDataSource . Span对象目前无法由ColumnDataSource “驱动”。 Each Span only draws one span, specified by its own location property.每个Span只绘制一个 span,由其自己的location属性指定。

You will need to update the location property individually on each Span object in order to update it.您需要单独更新每个Span object 上的location属性才能更新它。 Alternatively, if you absolutely want to be able to drive updates through a CDS, you could look at using a multi_line , segment , or ray glyph instead.或者,如果您绝对希望能够通过 CDS 驱动更新,您可以考虑改用multi_linesegmentray字形。 Those all have different ways to configure their coordinates, so you'd have to see which is most convenient to your use-case.它们都有不同的方式来配置它们的坐标,所以你必须看看哪种方式对你的用例最方便。 But they all come with one trade-off, which is that none of them have the full "infinite extent" that a Span supports.但它们都有一个权衡,那就是它们都没有Span支持的完整“无限范围”。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM