简体   繁体   English

手动更改散景图的 x 范围

[英]Manually change x range for Bokeh plot

So I'm trying to create a Bokeh plot for which I would like to be able to manually adapt the range of the X-Axis with a slider.所以我正在尝试创建一个散景图,我希望能够使用滑块手动调整 X 轴的范围。 Being a newbie I've only managed to get this far and despite researching this subject I haven't been able to solve this problem.作为一个新手,我只能做到这一步,尽管研究了这个主题,但我还是没能解决这个问题。

Here my code:这是我的代码:

from bokeh.layouts import column
from bokeh.models import CustomJS, ColumnDataSource, Slider
from bokeh.plotting import Figure, output_file, show
output_file("test.html")
x = [x*0.5 for x in range(0, 200)]
y = x
source = ColumnDataSource(data=dict(x=x, y=y))
plot = Figure(plot_width=600, plot_height=400, x_range=(0, 100))
plot.line('x', 'y', source=source, line_width=2, line_alpha=0.75)
callback = CustomJS(args=dict(x_range=plot.x_range), code="""
    var start = cb_obj.value
    x_range.set({"start": start, "end": start+10})
""")
slider = Slider (start=0, end=90, value=20, step=10)
slider.js_on_change('value', callback)
layout = column(slider, plot)
show(layout)

My biggest problem is to understand how I connect the CustomJS to my plot.我最大的问题是了解如何将 CustomJS 连接到我的情节。 I would gladly appreciate your help.我很乐意感谢您的帮助。

It has been answered at the Bokeh Google group已经在Bokeh Google group得到了解答

To reiterate, the only change needed is to replace x_range.set with x_range.setv .重申一下,唯一需要的更改是将x_range.set替换为x_range.setv

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

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