手动更改散景图的x范围 [英] Manually change x range for Bokeh plot

查看:63
本文介绍了手动更改散景图的x范围的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我试图创建一个散景图,我希望能够使用滑块手动调整X轴的范围. 作为一个新手,我只能做到这一点,尽管研究了这个主题,但我仍无法解决这个问题.

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. 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.

这是我的代码:

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)

我最大的问题是了解如何将CustomJS连接到绘图. 非常感谢您的帮助.

My biggest problem is to understand how I connect the CustomJS to my plot. I would gladly appreciate your help.

推荐答案

已在重申一下,唯一需要做的更改是将x_range.set替换为x_range.setv.

To reiterate, the only change needed is to replace x_range.set with x_range.setv.

这篇关于手动更改散景图的x范围的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆