gpt4 book ai didi

python - 将 Bokeh 图平移限制在定义的范围内

转载 作者:太空狗 更新时间:2023-10-30 01:01:41 25 4
gpt4 key购买 nike

我想知道是否可以限制 Bokeh 生成图的“平移”工具的范围?例如,假设我有这个简单的情节:

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 工具效果很好,但我可以继续平移直到我的图表消失。有什么方法可以限制平底锅吗?

最佳答案

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

您可以喂 y_rangex_range Bokeh 模型上的关键字参数 Range1d带有关键字参数的对象 bounds设置为元组以限制平移边界。

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的前两个位置参数用于设置轴的默认视口(viewport),边界独立于这些参数。


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

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

关于python - 将 Bokeh 图平移限制在定义的范围内,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23277066/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com