在bokeh中使用TapTool设置图形范围 [英] setting figure ranges using TapTool in bokeh

查看:111
本文介绍了在bokeh中使用TapTool设置图形范围的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在下面的示例中,我彼此之间有2个散点图.预期的行为是:

In the below example I have 2 scatter plots on top of each other. The intended behaviour is:

  • 点击上方图形中的一个点时,下方图形会放大到周围的区域
  • 单击下部图形中的一个点时,下部图形会放大到周围区域

我有第一个行为要运行,但是第二个行为似乎不起作用:x_range重置为覆盖数据的整个范围,而忽略了回调中的xrange.start=赋值./p>

I've got the first behaviour to run, but the second one doesn't seem to work: the x_range gets reset to cover the whole span of the data, ignoring the xrange.start= assignment in the callback.

# test_data_a is a pandas dataframe containing columns "x" and "y"
# test_data_b is a pandas dataframe containing columns "x" and "y"
f1=figure(width=950, tools="xwheel_zoom,box_zoom,reset,tap", height=200)
test_source1 = ColumnDataSource(data=dict(x=test_data_a.x, y=test_data_a.y))
test_source2 = ColumnDataSource(data=dict(x=test_data_b.x, z=test_data_b.z))
f1.circle("x", "y", fill_alpha=0.6, size=10, source=test_source1)


f2=figure(width=950, tools="reset,tap")
f2.circle("x", "z", fill_alpha=0.6, size=10, source=test_source2)

cb_click_testtop = CustomJS(args=dict(ts1=test_source1, ts2=test_source2, xrange=f2.x_range, yrange=f2.y_range), code="""
        index_selected=ts1.selected['1d'].indices[0]
        xmin=ts1.data['x'][index_selected]-0.5
        xmax=ts1.data['x'][index_selected]+0.5
        xrange.start=xmin
        xrange.end=xmax
""")

cb_click_testbot = CustomJS(args=dict(ts1=test_source1, ts2=test_source2, xrange=f2.x_range, yrange=f2.y_range), code="""
        index_selected=ts2.selected['1d'].indices[0]
        xmin=ts2.data['x'][index_selected]-0.5
        xmax=ts2.data['x'][index_selected]+0.5
        xrange.start=xmin
        xrange.end=xmax
""")
f1.add_tools(TapTool(callback=cb_click_testtop))
f2.add_tools(TapTool(callback=cb_click_testbot))


both= gridplot([[f1], [f2]])

show(both)

可以在这里中找到另一个(简单)示例,即使只绘制一张图,也会出现相同的问题.

Another (simpler) example can be found here, where the same problem appears even when drawing only 1 plot.

推荐答案

默认的DataRange1d范围仅在初始设置为 时响应用户对startend所做的更改.随后,DataRange1d要么遵循初始值,要么如果未设置初始值,则始终自动调整范围.要使这种对范围的显式控制起作用,请改用Range1d:

The default DataRange1d ranges only respond to user changes to start and end when they are set initially. Subsequently, a DataRange1d either respects the initial value, or always auto-ranges if one was not set. To make this kind of explicit control of ranges work, use a Range1d instead:

p=figure(x_range=(0,5)) 

这篇关于在bokeh中使用TapTool设置图形范围的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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