Bri*_*ian 35 python plot zoom axes bokeh
我在一个函数中创建一个数字,例如
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
Run Code Online (Sandbox Code Playgroud)
后来我想放大图:
fig = make_fig()
# <- zoom in on plot, like `set_xlim` from matplotlib
show(fig)
Run Code Online (Sandbox Code Playgroud)
如何在散景中进行程序化缩放?
Bri*_*ian 47
一种方法是在创建图形时使用简单元组进行处理:
figure(..., x_range=(left, right), y_range=(bottom, top))
Run Code Online (Sandbox Code Playgroud)
但你也可以设置x_range,并y_range直接在创建人物的属性.(我一直在寻找类似set_xlim或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)
Run Code Online (Sandbox Code Playgroud)
从 Bokeh 2.X 开始,似乎无法figure.{x,y}_range用Range1dfrom的新实例替换,DataRange1d反之亦然。
相反,必须设置figure.x_range.start并figure.x_range.end进行动态更新。
有关此问题的更多详细信息,请参阅https://github.com/bokeh/bokeh/issues/8421。
| 归档时间: |
|
| 查看次数: |
23184 次 |
| 最近记录: |