如何在散景图中引用特定的矩形?

问题描述 投票:0回答:1

我想找到绘制在顶部的矩形的参考。我似乎不知道该怎么做。

x = [x*0.005 for x in range(0, 200)]
y = x      

source = ColumnDataSource(data=dict(x=x, y=y))

plot = figure(width=400, height=400, x_range=(0, 1), y_range=(0, 1))

plot.line('x', 'y', source=source, line_width=3, line_alpha=0.6)

# the points to be plotted
x1 = .30
y1 = .30
w1 = .40
h1 = .20
 
# plotting the graph
plot.rect(x1, y1,w1,h1)

slider = Slider(start=0.1, end=4, value=1, step=.1, title="power")
slider.js_link('value', plot,'x1')
layout = column(slider, plot)

show(layout)

js_link 调用在绘图结构下的 Rect 中找不到 x1。 plot.rect 当然不起作用。

我怎样才能引用矩形?

谢谢!

python bokeh
1个回答
0
投票

正如评论中提到的 bigreddot,您可以在您的渲染器列表中解决

rect
plot
对象。这取决于您添加渲染器的顺序。要将
x
rect
值连接到滑块值,您可以使用
plot.renderers[1].glyph
.

下面的示例让您有机会通过使用滑块更改中心来移动矩形。

from bokeh.plotting import show, figure, output_notebook
from bokeh.models import ColumnDataSource, Slider
from bokeh.layouts import column
output_notebook()

x = [0, 1]
y = [0, 1]      

source = ColumnDataSource(data=dict(x=x, y=y))

plot = figure(width=400, height=400, x_range=(0, 1), y_range=(0, 1))

plot.line('x', 'y', source=source, line_width=3, line_alpha=0.6)

# the points to be plotted
x1 = .30
y1 = .30
w1 = .40
h1 = .20
 
# plotting the graph
plot.rect(x1, y1,w1,h1)

slider_x = Slider(start=0.1, end=1, value=x1, step=.1, title="x")
slider_x.js_link('value', plot.renderers[1].glyph,'x')
slider_y = Slider(start=0.1, end=1, value=y1, step=.1, title="y")
slider_y.js_link('value', plot.renderers[1].glyph,'y')
layout = column(slider_x, slider_y, plot)

show(layout)
© www.soinside.com 2019 - 2024. All rights reserved.