- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
我正在使用 Bokeh 创建 NetworkX 图的交互式可视化。我想要做的是,当我将鼠标悬停在特定节点上时,显示连接到该节点的所有边。
在 Bokeh 用户指南中有一个 example这或多或少满足了我的要求,但我对这个解决方案不满意,原因有二:
因此,我尝试了另一种方法:从头开始绘制所有边,但将它们的 visible
属性设置为 False
。然后创建一个字典,其中节点索引作为键,连接到该节点的边列表作为值。当鼠标悬停在节点上时,该节点的边缘应该将其 visible
属性更改为 True
。它看起来或多或少像这样:
global glob_edges_by_node_index
edges_by_node = {}
for edge in G.edges(data=True): # create the segments (G is a preexisting NetworkX graph)
u,v,d = edge
x_0 = pos[u][0] # pos is a preexisting dictionary of x and y values for each node
y_0 = pos[u][1]
x_1 = pos[v][0]
y_1 = pos[v][1]
width = 0.03*d['weight']
highlit_edge = p.segment(x0=[x_0],x1=[x_1],y0=[y_0],y1=[y_1],color='#379bdd',line_width=width) # p is a preexisting Bokeh figure
highlit_edge.visible = False # all segments are invisible at the start
edges_by_node[u].append(highlit_edge) # put the segment into both nodes' dictionary entries
edges_by_node[v].append(highlit_edge)
id_to_index = {}
edges_by_node_index = {}
i = 0
for node_id in G.nodes(): # convert the dict keys from their original IDs to the indices seen by Bokeh
id_to_index[node_id] = i
edges_by_node_index[i] = edges_by_node[node_id]
i = i + 1
global glob_edges_by_node_index = edges_by_node_index
nodesource = ColumnDataSource(data=dict(x=x,y=y,sizes=nodesizes,colours=nodecolours)) # refers to preexisting data about the nodes
cr = p.circle('x','y',color='colours',alpha=0.7,hover_color='colours',hover_alpha=1.0,size='sizes',line_width=1,line_color='#000000',hover_line_color='#000000',source=nodesource) # draw the nodes themselves
p.add_tools(HoverTool(tooltips=None,callback=CustomJS.from_py_func(on_hover),renderers=[cr]))
def on_hover(window=None):
indices = cb_data['index']
for ind in indices:
highlit_edges = glob_edges_by_node_index[ind]
for highlit_edge in highlit_edges:
highlit_edge.visible = True # set edges to visible if they're in the dict entry of the hovered-over node
这行不通,我对如何修复它有点困惑。尤其是 cb_data
的使用对我来说是个谜——尽管进行了大量的谷歌搜索,但我仍无法找到关于 cb_data
包含哪些信息、在哪些方面的清晰全面的引用格式,以及如何访问它。任何帮助将不胜感激!
最佳答案
您可以添加悬停工具以在悬停时突出显示连接的边缘,还可以将默认线 alpha 设置为零:
import networkx as nx
from bokeh.models import Range1d, MultiLine, Circle, HoverTool
from bokeh.models.graphs import from_networkx, EdgesAndLinkedNodes
from bokeh.plotting import figure, show
G=nx.karate_club_graph()
plot = figure(plot_width=400, plot_height=400,
x_range=Range1d(-1.1,1.1), y_range=Range1d(-1.1,1.1))
plot.add_tools(HoverTool(tooltips=None))
r = from_networkx(G, nx.circular_layout, scale=1, center=(0,0))
r.node_renderer.glyph = Circle(size=15, fill_color='#2b83ba')
r.node_renderer.hover_glyph = Circle(size=15, fill_color='#abdda4')
r.edge_renderer.glyph = MultiLine(line_alpha=0, line_width=5) # zero line alpha
r.edge_renderer.hover_glyph = MultiLine(line_color='#abdda4', line_width=5)
r.inspection_policy = EdgesAndLinkedNodes()
plot.renderers.append(r)
show(plot)
关于python - Bokeh 中的网络图形 : displaying a node's connections when hovering over the node,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38984889/
我一直在为此而苦苦挣扎。我想插入一个图像,并将其“靠近”讨论该图像的文本,但是该页面上的文本将围绕图像环绕/流动。 我已将图像转换为eps格式。最初,我尝试使用图形环境(\begin {figure}
我在用户界面中创建了管理控制台,管理员可以在其中执行所有操作,例如创建、删除用户、向用户分配应用程序以及从用户界面删除用户的应用程序访问权限 我厌倦了使用 Microsoft 图形 API 和 Azu
我在用户界面中创建了管理控制台,管理员可以在其中执行所有操作,例如创建、删除用户、向用户分配应用程序以及从用户界面删除用户的应用程序访问权限 我厌倦了使用 Microsoft 图形 API 和 Azu
我想为计算机图形学类(class)做一个有趣的项目。我知道那里有很多文献(即 SIGGRAPH session 论文)。我对计算机图形学(即图像处理、3D 建模、渲染、动画)兴趣广泛。但是,我只学了
我试图在 MaterializeCSS 网站上创建一些类似于这个的图形,但我不知道它来自哪里,我查看了整个 MaterializeCSS 网站,它不是框架的一部分,我找不到在代码中他们使用的是什么 我
我有一个包含 1 到 6 之间的各种数字的 TextView ,每个数字在每一行上代表一次,例如 123456 213456 214356 ...... 我希望能够绘制一条蓝线来跟随单个数值在列表中向
我目前在 Windows 7 上使用 Netbeans 和 Cygwin,我希望用 C 语言编写一个简单的 2D 游戏。 我设法找到的大多数教程都使用 Turbo C 提供的 graphics.h,C
亲爱的,我正在尝试将 kaggle 教程代码应用于 Iris 数据集。 不幸的是,当我执行图表的代码时,我只能看到这个输出而看不到任何图表: matplotlib.axes._subplots.Axe
我需要加快我正在处理的一些粒子系统的视觉效果。令人眼前一亮的是添加混合、积累以及粒子上的轨迹和发光。目前我正在手动渲染到浮点图像缓冲区,在最后一分钟转换为无符号字符,然后上传到 OpenGL 纹理。为
在研究跨网络的最短路径算法时,我想生成网络图片。我想代表节点(圆圈)、链接(线)、遍历链接的成本(链接线中间的数字)和链接的容量(链接线上它代表的节点旁边的数字)在这张图中。是否有任何库/软件可以帮助
尽管我已将应用程序从库添加到 Azure AD,但我无法看到何时尝试提取数据。但我可以看到添加的自定义应用程序。就像我添加了 7 个应用程序一样; 2 个来自图库(Google 文档、一个驱动器)和
因此,我正在构建一个系统,该系统具有“人员”,“银行帐户”和“银行帐户交易”。 我需要能够回答以下问题: “将所有与1/2/3度有联系的人归还给特定的人”, “返回年龄在40岁以上的所有人” “从德国
我在 JFrame 构造函数中有以下简单代码 super(name); setBounds(0,0,1100,750); setLayout(null); setVis
(这是java)我有一个椭圆形,代表一个单位。我希望椭圆形的颜色代表单位的健康状况。因此,一个完全健康的单位将是全绿色的。随着单位生命值的降低,椭圆形开始从底部填充红色。因此,在 50% 生命值下,椭
我目前正在开发一个学校项目。我们必须制作一个Applet,我选择了JApplet。由于某种原因,我用来显示特定字符串的面板将不会显示。这里可能有什么问题?请指出我正确的方向。另外,我看了一些教程,
我正在尝试创建一个 Simon game 。我正在编写游戏程序,但遇到了问题。我希望程序从队列中读取游戏中之前存在的所有值,并以正确的顺序将它们的颜色变为闪烁(我选择将它们变为灰色,然后在第二秒后恢复
我正在尝试创建一个框架,该框架在同一框架的顶部有一个图形面板(通过布局),在其下方有一个按钮/标签面板。到目前为止,我似乎已经能够将它们放在同一个框架上,但与按钮/标签面板相比,图形面板非常小....
我用 Java 编写了一个解决数独问题的代码,并使用 Java Applet 来设计它。现在,我尝试使用 Java Swing 使其看起来更好,并添加一些功能,例如“保存”数独板等。不幸的是,我对 J
就目前情况而言,这个问题不太适合我们的问答形式。我们希望答案得到事实、引用资料或专业知识的支持,但这个问题可能会引发辩论、争论、民意调查或扩展讨论。如果您觉得这个问题可以改进并可能重新开放,visit
我现在尝试了 8 个多小时来解决这个问题,但无法弄清楚,请帮助找出我的代码有什么问题。 int main() { int gd = DETECT, gm; float ANGLE =
我是一名优秀的程序员,十分优秀!