将散景图平移限制在定义的范围内 [英] Limit bokeh plot pan to defined range

查看:82
本文介绍了将散景图平移限制在定义的范围内的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道是否有可能限制散景生成图的平移"工具的范围?例如,假设我有一个简单的情节:

I was wondering if it were possible to limit the range of the "pan" tool for bokeh generated plots? For example, say I had this simple plot:

from bokeh.plotting import output_file, rect, show
output_file('test.html')
rect([10,20,30], [10,20,30], width=[1,2,3], color=['red','blue','green'], height=5, plot_width=400, plot_height=400, tools = "ypan,box_zoom,reset")
show()

ypan工具效果很好,但是我可以继续平移,直到我的图形消失.有什么办法可以约束锅吗?

The ypan tool works great, but I could keep panning until my graph disappears. Is there any way I can constrain the pan?

推荐答案

此问题首次提出后,添加了平移/缩放限制功能.

The pan/zoom limit feature has been added after this question was first posed.

您可以将y_rangex_range关键字参数提供给bokeh模型上的Range1d对象,并将关键字参数bounds设置为元组以限制平移边界.

You can feed the y_range or x_range keyword arguments on a bokeh model a Range1d object with the keyword argument bounds set to a tuple to limit the pan boundaries.

from bokeh.plotting import figure
from bokeh.models import Range1d

fig = figure(y_range=Range1d(bounds=(0, 1)),
             x_range=Range1d(bounds=(0, 1)))

请注意,Range1d的前两个位置参数用于设置轴的默认视口,并且边界与这些参数无关.

Note that the Range1d's first two positional arguments are for setting the default view-port for an axis, and the bounds is independent of those arguments.

如果您希望边界受范围值限制,则可以传递边界auto:

If you want your bounds to be limited by the range values, then you can pass bounds auto:

Range1d(0, 1, bounds="auto")

这篇关于将散景图平移限制在定义的范围内的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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