简体   繁体   English

如何为散景中的字形设置悬停颜色?

[英]How to set Hover color for glyphs in Bokeh?

There are two ways to add glyphs in Bokeh.有两种方法可以在散景中添加字形。 I prefer the second way as it gives more flexibility with Hovers and legends.我更喜欢第二种方式,因为它为悬停和图例提供了更大的灵活性。 I cannot find the option to set hover color in the second method.我在第二种方法中找不到设置悬停颜色的选项。 Is there a way to do that?有没有办法做到这一点?

from bokeh.layouts import gridplot
from bokeh.models import ColumnDataSource, CDSView, IndexFilter
from bokeh.plotting import figure, show
from bokeh.io import curdoc, output_notebook, output_file, export_png    
from bokeh.models import (
  ColumnDataSource, Circle, HoverTool,Grid, TapTool,PanTool, WheelZoomTool, BoxSelectTool,ZoomInTool, ZoomOutTool, CDSView, GroupFilter)

curdoc().clear()
output_notebook()

source = ColumnDataSource(data=dict(x=[1, 2, 3, 4, 5], y=[1, 2, 3, 4, 5]))
view = CDSView(source=source, filters=[IndexFilter([0, 2, 4])])

#---------------------Method1-----------------------------
tools = ["box_select", "hover", "reset"]
p = figure(plot_height=300, plot_width=300, tools=tools)
p.circle(x="x", y="y", size=10, hover_color="red", source=source)

#---------------------Method2-----------------------------
p_glypg = figure(plot_height=300, plot_width=300, tools="pan,wheel_zoom,box_zoom,reset,zoom_in,zoom_out,save")
circle = Circle(x="x", y="y", size=10)
c = p_glypg.add_glyph(source, circle)
c_hover = HoverTool(renderers=[c], tooltips=[('x', '@x')])
p_glypg.add_tools(c_hover) 

show(gridplot([[p,p_glypg]]))

在此处输入图片说明

In the same way as selected/nonselected can be added at the low level, as described in the documentation:以与 selected/nonselected 相同的方式可以在低级别添加,如文档中所述:

https://docs.bokeh.org/en/latest/docs/user_guide/styling.html#selected-and-unselected-glyphs https://docs.bokeh.org/en/latest/docs/user_guide/styling.html#selected-and-unselected-glyphs

circle = Circle(x="x", y="y", size=10)
hover_circle = Circle(x="x", y="y", size=10, fill_color="red")
c = p_glypg.add_glyph(source, circle, hover_glyph=hover_circle)

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

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