首页 > 解决方案 > 如何通过将鼠标悬停在散景中的不同字形上来更改字形组的颜色?或显示描述关系的线条

问题描述

我有以下情节

在此处输入图像描述

使用

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)

当我悬停在底部正方形上时,我想更改底部三个圆圈的颜色,而当顶部正方形悬停在顶部时,我想更改顶部 2 个圆圈的颜色?假设我有一个识别这种关系的数据框。

有没有办法在散景中做到这一点?

如果我还可以显示从正方形到圆圈的线条,仅当我将鼠标悬停在正方形上时描绘关系,那就更好了。

标签: pythonbokeh

解决方案


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


推荐阅读