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

老子叫甜甜 提交于 2019-12-24 06:11:09

问题


I have the following plot

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:


You can use CustomJS for Hover to update properties of other glyphs, such as color or visibility.



来源:https://stackoverflow.com/questions/54119349/how-to-change-color-of-group-of-glyphs-by-hovering-on-a-different-glyph-in-bokeh

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!