简体   繁体   English

散景:绘制多个图形时的跨度

[英]Bokeh: Span when plotting multiple graphs

I'm fairly new to Bokeh so still probably missing something with it, but I keep running into issues when trying to use Span on multiple plots if I'm generating the plots in a loop. 我对Bokeh相当陌生,因此仍然可能缺少一些东西,但是如果我在循环中生成图,则在尝试在多个图上使用Span时会遇到问题。 Here's what I'm trying: 这是我正在尝试的:

titleString = 'Test Plot'
plotVals = [1, 2]
upperLimit = Span(location=6, dimension='width', line_color='red', line_dash='dashed', line_width=1)
lowerLimit = Span(location=-6, dimension='width', line_color='red', line_dash='dashed', line_width=1)
xVals = [0,1,2,3,4]
yVals = [2,4,3,4,2]
for t in enumerate(plotVals):
    print(t[1])
    imgTitle = 'Span Test ' + str(t[0])
    p = figure(title=imgTitle, plot_width=800, plot_height=450, y_range=(-8, 8), x_range=(-4,8))
    p.add_layout(upperLimit)
    p.add_layout(lowerLimit)
    p.circle(xVals,yVals, size=5)            
    show(p)
    reset_output()

The first graph comes out as expected, but the second fails with the following message: 第一张图按预期显示,但是第二张显示以下消息失败:

ValueError: object to be added already has 'plot' attribute set ValueError:要添加的对象已经设置了“绘图”属性

I assume I'm doing something stupid. 我认为我在做一些愚蠢的事情。 Can someone point me in the right direction? 有人可以指出我正确的方向吗?

Renderers (including annotations such as Span ) may not be shared between multiple plots. 渲染器(包括诸如Span注释)可能无法在多个图之间共享。 You will need to create new spans for each plot. 您将需要为每个图创建新的跨度。

If you are explicitly trying to reuse span configurations defined outside the loop, you might rewrite similar to: 如果要显式地尝试重用循环外定义的跨度配置,则可能类似于以下内容进行重写:

titleString = 'Test Plot'
plotVals = [1, 2]

upper_kw = dict(location=6, dimension='width', line_color='red', line_dash='dashed', line_width=1)
lower_kw = dict(location=-6, dimension='width', line_color='red', line_dash='dashed', line_width=1)

xVals = [0,1,2,3,4]
yVals = [2,4,3,4,2]
for t in enumerate(plotVals):
    imgTitle = 'Span Test ' + str(t[0])
    p = figure(title=imgTitle, plot_width=800, plot_height=450, y_range=(-8, 8), x_range=(-4,8))

    p.add_layout(Span(**upper_kw))
    p.add_layout(Span(**lower_kw))

    p.circle(xVals, yVals, size=5)            
    show(p)
    reset_output()

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

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