How to change color of group of glyphs by hovering on a different glyph in Bokeh? Or show lines depicting the relationship

时间:2019-01-09 22:30:02

标签: python bokeh

I have the following plot

enter image description here

using

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, Square, HoverTool,Grid, TapTool,PanTool, WheelZoomTool, BoxSelectTool,ZoomInTool, ZoomOutTool, CDSView, GroupFilter)

curdoc().clear()
output_notebook()

source1 = ColumnDataSource(data=dict(x=[1, 2, 3, 4, 5], y=[1, 2, 3, 4, 5]))
source2 = ColumnDataSource(data=dict(x=[3, 4], y=[2, 3]))

p = 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)

square = Square(x="x", y="y", size=10)
hover_square = Square(x="x", y="y", size=10, fill_color="red")

c = p.add_glyph(source1, circle)
s = p.add_glyph(source2, square, hover_glyph=hover_square)

c_hover = HoverTool(renderers=[c,s], tooltips=[('x', '@x')])
p.add_tools(c_hover)

show(p)

I want to change the color of bottom three circles when I hover on the bottom square and top 2 circles when top square is hovered on? Let's say I have a dataframe which identifies this relationship.

Is there a way to do this in Bokeh?

It would be even better if I can also show lines from a square to circles depicting the relationship only when a I hover on a square.

1 个答案:

答案 0 :(得分:0)

您可以使用CustomJS for Hover更新其他字形的属性,例如颜色或可见性。