繁体   English   中英

如何获取python侧图中的单击坐标?

[英]How can I get the coordinates of a click in a plot on python side?

我有一个带有圆圈的绘图,我希望用户能够选择圆圈,然后根据圆圈在python端做一些事情。

我尝试了JS回调,但收到错误消息:

警告:bokeh.embed.util:您正在生成独立的HTML / JS输出,但是尝试使用真实的Python回调(即on_change或on_event)。 此组合无效。 仅JavaScript回调可与独立输出一起使用。 有关使用Bokeh进行JavaScript回调的更多信息,请参见:

http://docs.bokeh.org/en/latest/docs/user_guide/interaction/callbacks.html另外,要使用真实的Python回调,可以使用Bokeh服务器应用程序。 有关构建和运行Bokeh应用程序的更多信息,请参见: http : //docs.bokeh.org/en/latest/docs/user_guide/server.html

如果您想尝试执行以下代码。

from bokeh.plotting import figure, output_file, show

output_file("openurl.html")

p = figure(plot_width=400, plot_height=400, tools="tap", title="Click the Dots")

source = ColumnDataSource(data=dict(
    x=[1, 2, 3, 4, 5],
    y=[2, 5, 8, 2, 7],
    color=["navy", "orange", "olive", "firebrick", "gold"]
    ))

p.circle('x', 'y', color='color', size=20, source=source)```


我不太了解您的问题,但是您可以使用悬停工具来添加交互,或者使用LabelSet来显示x / y和点。

from bokeh.plotting import figure
from bokeh.io import show, output_notebook
output_notebook()

p = figure(plot_width=400, plot_height=400, tools="tap, reset, hover", title="Click 
the Dots", tooltips = [('x', '@x'),('y','@y')])

source = ColumnDataSource(data=dict(
    x=[1, 2, 3, 4, 5],
    y=[2, 5, 8, 2, 7],
    color=["navy", "orange", "olive", "firebrick", "gold"]
    ))

p.circle('x', 'y', color='color', size=20, source=source)
show(p)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM