python - 如何通过将鼠标悬停在散景中的不同字形上来更改字形组的颜色?或显示描述关系的线条
问题描述
我有以下情节
使用
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 个圆圈的颜色?假设我有一个识别这种关系的数据框。
有没有办法在散景中做到这一点?
如果我还可以显示从正方形到圆圈的线条,仅当我将鼠标悬停在正方形上时描绘关系,那就更好了。
解决方案
您可以使用CustomJS for Hover来更新其他字形的属性,例如颜色或可见性。
推荐阅读
- c - 指针类型不兼容
- python - pyopengl - 纹理未按应有的方式渲染
- templates - Vue3 TypeError:模板 ref.value 为空
- jython - 在 TigerJython 中检测右键单击
- javascript - 单击功能将使用 AJAX 的数据发送到 php 文件以将其保存在数据库中只工作一次
- django - `graphene_django` 的`op_name` 参数
- html - 提交按钮不适用于 Android,但适用于 PC 和 iPhone
- azure - 如何为 Azure kubernetes LoadBalancer 使用静态外部 IP?
- flutter - Flutter - 如何动态PageView?
- python - 连接存储在一个对象中的多个列表