admin管理员组文章数量:1416050
In bokeh.models.actions.Action
, there is a callback
class for user defined callback. It passes the current plot_object
as cb_obj
implicitly.
However, I don't know how to access the data from the plot_object
.
fig = figure()
fig.circle(x=[1,2,3], y=[4,5,6])
tap_tool.action = Callback(
code="""
alert('clicked')
console.log(cb_obj)
""")
How can I access the information, e.g. x, y of a clicked circle? In a template string we can use @variable
or $x
to get information about each data point.
Furthermore, it seems to me that there is only 1 Circle Glyph
, despite of 3 circles. So glyph has nothing to do with the number of data points, is it correct?
Does cb_obj
refer to this Glyph
, or the glyphRenderer
that contains this glyph?
In the docs an example shows:
var inds = cb_obj.get('selected')['1d'].indices;
var d1 = cb_obj.get('data');
Where does select, id, indices, data
e from? What's the structure of cb_obj
.
In bokeh.models.actions.Action
, there is a callback
class for user defined callback. It passes the current plot_object
as cb_obj
implicitly.
However, I don't know how to access the data from the plot_object
.
fig = figure()
fig.circle(x=[1,2,3], y=[4,5,6])
tap_tool.action = Callback(
code="""
alert('clicked')
console.log(cb_obj)
""")
How can I access the information, e.g. x, y of a clicked circle? In a template string we can use @variable
or $x
to get information about each data point.
Furthermore, it seems to me that there is only 1 Circle Glyph
, despite of 3 circles. So glyph has nothing to do with the number of data points, is it correct?
Does cb_obj
refer to this Glyph
, or the glyphRenderer
that contains this glyph?
In the docs an example shows:
var inds = cb_obj.get('selected')['1d'].indices;
var d1 = cb_obj.get('data');
Where does select, id, indices, data
e from? What's the structure of cb_obj
.
2 Answers
Reset to default 2As of Bokeh 0.9.0, for TapTool
actions, the value of cb_obj
is the data source for the glyph that reported the hit. This example shows how to access the data columns:
https://docs.bokeh/en/latest/docs/user_guide/interaction/callbacks.html#customjs-for-tools
You can actually inspect the object through:
console.log(cb_data);
console.log(cb_obj);
For example use this callbacks to inspect the contents of both object:
scode = """
console.log(cb_obj);
console.log(cb_data);
"""
taptool.callback = CustomJS(args=dict(source=source),code = scode)
If you run in chrome you will see the content of cb_obj and cb_data in your logs (View-Developer-Javascripts Console)
本文标签: javascriptHow to use cbobj in callbacks in bokehStack Overflow
版权声明:本文标题:javascript - How to use cb_obj in callbacks in bokeh? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745247064a2649602.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论