Jupyter Python Notebook:交互式散点图,其中每个数据点与其自己的图形相关联?

时间:2016-09-22 20:01:43

标签: python visualization jupyter interactive bokeh

考虑一组数据点。每个数据点由两个数字和两个数组组成。例如,这两个数字可能是两个参数的值,两个数组可能代表相关的时间进程数据。我想在Jupyter Python Notebook中生成内联散点图,其中我将两个数字相互关联。另外,我希望散点图是交互式的,这样当我将光标悬停在数据点上时,会出现第二个图形,其中两个数组相互绘制。我该怎么办?

Here是Bokeh中的一个示例,它接近我想要的但它只显示与每个点而不是图形相关联的浮动文本框。我应该说,如果图形没有浮动,而是锚定在散点图附近,我会更喜欢。

感谢。

1 个答案:

答案 0 :(得分:0)

“{3}}中的”定义回调“可能有所帮助。不方便,不完美,但可以实现你所描述的。

from bokeh.models import ColumnDataSource, OpenURL, TapTool
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)

url = "http://www.colors.commutercreative.com/@color/"
taptool = p.select(type=TapTool)
taptool.callback = OpenURL(url=url)

show(p)