如何在 Bokeh 中完成 `set_xlim` 或 `set_ylim` ?

2024-01-02

我在函数中创建一个图形,例如

import numpy
from bokeh.plotting import figure, show, output_notebook
output_notebook()

def make_fig():
    rows = cols = 16
    img = numpy.ones((rows, cols), dtype=numpy.uint32)
    view = img.view(dtype=numpy.uint8).reshape((rows, cols, 4))
    view[:, :, 0] = numpy.arange(256)
    view[:, :, 1] = 265 - numpy.arange(256)
    fig = figure(x_range=[0, c], y_range=[0, rows])
    fig.image_rgba(image=[img], x=[0], y=[0], dw=[cols], dh=[rows])
    return fig

后来我想放大图:

fig = make_fig()
# <- zoom in on plot, like `set_xlim` from matplotlib
show(fig)

如何在散景中进行编程缩放?


一种方法是在创建图形时使用简单的元组来进行操作:

figure(..., x_range=(left, right), y_range=(bottom, top))

但您也可以设置x_range and y_range直接创建图形的属性。 (我一直在寻找类似的东西set_xlim or set_ylim来自 matplotlib。)

from bokeh.models import Range1d

fig = make_fig()
left, right, bottom, top = 3, 9, 4, 10
fig.x_range=Range1d(left, right)
fig.y_range=Range1d(bottom, top)
show(fig)
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

如何在 Bokeh 中完成 `set_xlim` 或 `set_ylim` ? 的相关文章

随机推荐