2016-09-22 333 views
1

考慮一組數據點。每個數據點由兩個數字和兩個數組組成。例如,這兩個數字可能是兩個參數的值,兩個數組可能表示相關的時間過程數據。我想在Jupyter Python Notebook中生成一個內聯散點圖,在這個圖表中我將這兩個數字相互關聯。此外,我希望散點圖是交互式的,因此,當我將光標懸停在數據點上時,會出現第二個圖,在這個圖中兩個數組相互對齊。我應該怎麼做?Jupyter Python Notebook:交互式散點圖,其中每個數據點都與其自己的圖相關聯?

Here是Bokeh中的一個例子,它接近我想要的,但它只顯示與每個點相關的浮動文本框而不是圖。我應該說,如果圖形沒有浮動,而是靠近散點圖,我會更喜歡。

謝謝。

回答

0

Bokeh documentation「定義回調」可能會有所幫助。不方便,不完美,但可以實現你所描述的。

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)