散景回调以更新图像 [英] Bokeh callback for image update
问题描述
我有一个散景图,可以显示图像,可以通过滑块更改它(并且应该定期更新)(类似于此问题
I have a Bokeh plot that can display an image, which can be changed by a slider (and also should update regularly) (similar to this question Sliding through images with Bokeh Slider). So the url of the image changes and Bokeh reloads the image. Is there a way to attach a callback function to the load of the image?
推荐答案
从散景1.4.0
开始,图像加载没有回调. ImageURL
字形并不是由核心开发人员AFAIK广泛使用的,而且我们不能总是预期每个用户可能想要的每个用例.因此,我们使Bokeh本身具有可扩展性,因此,我目前建议的最好办法是使用自定义扩展名扩展Bokeh.用于创建自定义扩展的文档在这里:
As of Bokeh 1.4.0
there is no callback on the image load. The ImageURL
glyph is not one that is much used by the core developers, AFAIK, and we can't always anticipate every use case that every user might want. For this reason, we have made Bokeh itself extensible, so the best I can suggest at the moment is to extend Bokeh with a custom extension. The documentation for creating custom extensions is here:
http://docs.bokeh.org/en/latest/docs/user_guide/extensions.html
在缩写形式中,您将创建一个类似这样的类,该类添加一个callback
属性,并为您的自定义ImageURL
字形提供JavaScript实现:
In abbreviated forms, you'd create a class like this that adds a callback
property, and supplies the JavaScript implementation for your custom ImageURL
glyph:
class MyImageURL(ImageURL):
callback = Instance(Callback, help="A callback to run when images load")
__implementation__ = JAVASCRIPT_CODE_HERE
然后它可以像任何低级glyoh一样使用:
Then it can be used like any low level glyoh:
my_glyph = MyImageURL(...)
source = ColumnDataSource(...)
plot.add_glyph(source, my_glyph)
这篇关于散景回调以更新图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!