2017-01-17 17 views
0

私はBokehを実験していて、ホルトゥルールに不満を感じています。対象となる基本的なツールチップの1つとして塗りつぶしの色を示します。ホバーのツールチップにBokehの色が表示されない

http://bokeh.pydata.org/en/latest/docs/user_guide/tools.html#hover-tool

私がテストを試してみましたが、色がhovertoolに表示されません。それは私に "???"それはあなたがそれを理解できない入力を与えると通常それを完全に無視します。誰もが基本的なツールチップの1つを表示しない理由についての手掛かりを持っていますか?

Example Graph

from bokeh.plotting import figure, output_file, show, ColumnDataSource 
from bokeh.models import HoverTool 

output_file("toolbar.html") 

source = ColumnDataSource(
     data=dict(
      x=[1, 2, 3, 4, 5], 
      y=[2, 5, 8, 2, 7], 
      desc=['A', 'b', 'C', 'd', 'E'], 
     ) 
    ) 

hover = HoverTool(
     tooltips=[ 
      ("fill color", "$color[hex, swatch]:fill_color"), 
      ("index", "$index"), 
      ("(x,y)", "($x, $y)"), 
      ("desc", "@desc"),    
     ] 
    ) 

p = figure(plot_width=400, plot_height=400, tools=[hover], 
      title="Mouse over the dots") 


p.circle('x', 'y', size=20, source=source, fill_color="black") 

show(p) 

答えて

1

ホバーツールチップは、実際の列の列データソースのの値を検査することができます。固定値(fill_color="black")を指定しているため、検査する列はありません。さらに、特殊なホバーフィールド$colorhexは、16進の色文字列のみを認識します。ここで

が動作するように修正してコードです:

from bokeh.plotting import figure, output_file, show, ColumnDataSource 
from bokeh.models import HoverTool 

output_file("toolbar.html") 

source = ColumnDataSource(
     data=dict(
      x=[1, 2, 3, 4, 5], 
      y=[2, 5, 8, 2, 7], 
      desc=['A', 'b', 'C', 'd', 'E'], 
      fill_color=['#88ffaa', '#aa88ff', '#ff88aa', '#2288aa', '#6688aa'] 
     ) 
    ) 

hover = HoverTool(
     tooltips=[ 
      ("index", "$index"), 
      ("fill color", "$color[hex, swatch]:fill_color"), 
      ("(x,y)", "($x, $y)"), 
      ("desc", "@desc"), 
     ] 
    ) 

p = figure(plot_width=400, plot_height=400, tools=[hover], 
      title="Mouse over the dots") 


p.circle('x', 'y', size=20, source=source, fill_color="fill_color") 

show(p) 

enter image description here

+0

面白い、私はそれがサークルラインから塗りつぶしの色を引っ張った仮定のです。知っておいて、助けてくれてありがとう! – BikeControl

関連する問題