如何在Bokeh中完成`set_xlim`或`set_ylim`? [英] How can I accomplish `set_xlim` or `set_ylim` in Bokeh?
本文介绍了如何在Bokeh中完成`set_xlim`或`set_ylim`?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在函数中创建一个图形,例如
I create a figure in a function, e.g.
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)
如何在bokeh中进行程序化缩放?
How can I do programmatic zoom in bokeh?
推荐答案
一种方法是在创建图形时使用简单的元组创建事物:
One way is to can things with a simple tuple when creating a figure:
figure(..., x_range=(left, right), y_range=(bottom, top))
但是,您也可以直接设置已创建图形的x_range
和y_range
属性. (我一直在从matplotlib寻找类似set_xlim
或set_ylim
的东西.)
But you can also set the x_range
and y_range
properties of a created figure directly. (I had been looking for something like set_xlim
or set_ylim
from 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)
这篇关于如何在Bokeh中完成`set_xlim`或`set_ylim`?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文