如何在Bokeh中完成`set

编程入门 行业动态 更新时间:2024-10-26 19:26:03
本文介绍了如何在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

本文发布于:2023-07-18 08:23:52,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1142808.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:如何在   Bokeh   set

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!