使用hover_line_alpha时散景线“消失”

时间:2018-07-10 00:19:33

标签: python bokeh

我正在使用Bokeh程序包绘制折线图。

当我将鼠标悬停在其上方时,我希望给定的行加粗(alpha增大)。 我添加了一个悬停工具,然后在折线图中添加了“ hover_line_alpha = 0.6”。

但是,当我将鼠标悬停在给定线上的点上时,该线完全消失!

您能帮我解决这个问题吗?

下面的代码,以便您了解我的逻辑。

谢谢, 罗斯

# Code in Question
from bokeh.io import output_notebook, show, output_file
from bokeh.plotting import figure
from bokeh.models import ColumnDataSource, HoverTool

output_notebook()

# set out axes
x = 'time_rnd'
y = 'count'

# set colour palette
col_brew = ['#8dd3c7','#ffffb3','#bebada','#fb8072','#80b1d3','#fdb462','#b3de69','#fccde5','#d9d9d9','#bc80bd','#ccebc5','#ffed6f']

# map out figure
plot = figure(tools='box_select, lasso_select, save' ,x_axis_type='datetime')

# add HoverTool
hover_info = [('time', '@hover_time'),
          ('word', '@word'),
          ('count', '@count')]
hover = HoverTool(names=['use'],tooltips=hover_info,
              mode='mouse',
              show_arrow=True
             )
plot.add_tools(hover)


### FOR LOOP OF PLOT [THIS IS WHERE THE ISSUE MANIFESTS]

for i in top_wds_test:

  df_eng_word = df_eng_timeline[df_eng_timeline['word']==i]

  source = ColumnDataSource(df_eng_word)

  plot.line(x, y, line_width = 3, 
        line_alpha = 0.1, line_color=col_brew[top_wds.index(i)], 
        hover_line_alpha = 0.6,
        #hover_line_color = 'black',
        #hover_line_color = col_brew[top_wds.index(i)], 
        source = source, legend=i, name = 'use'
       )

  plot.circle(x, y, fill_color='white', size=5, 
          selection_color='green',
          nonselection_fill_color='grey',nonselection_fill_alpha=0.4, 
          hover_color='red',
          source = source, name = 'use')

# add legend
plot.legend.location = "top_left"
plot.legend.label_text_font_style = 'bold'

# materialize the plot
show(plot)

1 个答案:

答案 0 :(得分:1)

渲染器共享数据源时似乎存在问题。但是,如果让Bokeh为每个字形创建一个新的单独的源,则可以使用(Bokeh> = {0.13.0)。

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

p = figure(tools="hover", tooltips="$name: @$name")

data=dict(x=[1,2,3], y1=[2,6,5], y2=[6,2,3])

p.line('x', 'y1', color="navy", line_width=3, source=data,
       alpha=0.1, hover_color="navy", hover_alpha=0.6, name="y1")

p.line('x', 'y2',color="firebrick", line_width=3, source=data,
       alpha=0.1, hover_color="firebrick", hover_alpha=0.6, name="y2")

show(p)

enter image description here