首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >节点Hover效应

节点Hover效应
EN

Stack Overflow用户
提问于 2019-04-24 09:15:50
回答 1查看 797关注 0票数 0

当鼠标放在networkx生成的节点上时,我试图显示节点属性(如: words)。是否有可能让这一切成为可能。所有这些特性都应该在PyQt5应用程序中进行裁剪。

示例:

代码语言:javascript
复制
 #A bit of idea
    for i, elrow in df.iterrows():
        G.add_nodes(elrow[0], elrow[1], attr_dict=elrow[2:].to_dict(), weight=elrow(3)) #Just giving an instance

如何获取attr_dict中的所有数据作为鼠标悬停时的节点属性

EN

回答 1

Stack Overflow用户

发布于 2019-04-24 13:20:53

您应该使用博克库来进行这种可视化。

您可以为您的问题这里找到确切的解决方案

代码语言:javascript
复制
import networkx as nx

from bokeh.io import show, output_file
from bokeh.models import Plot, Range1d, MultiLine, Circle, HoverTool, BoxZoomTool, ResetTool
from bokeh.models.graphs import from_networkx
from bokeh.palettes import Spectral4

# Prepare Data
G = nx.karate_club_graph()

SAME_CLUB_COLOR, DIFFERENT_CLUB_COLOR = "black", "red"
edge_attrs = {}

for start_node, end_node, _ in G.edges(data=True):
    edge_color = SAME_CLUB_COLOR if G.nodes[start_node]["club"] == G.nodes[end_node]["club"] else DIFFERENT_CLUB_COLOR
    edge_attrs[(start_node, end_node)] = edge_color

nx.set_edge_attributes(G, edge_attrs, "edge_color")

# Show with Bokeh
plot = Plot(plot_width=400, plot_height=400,
            x_range=Range1d(-1.1, 1.1), y_range=Range1d(-1.1, 1.1))
plot.title.text = "Graph Interaction Demonstration"

node_hover_tool = HoverTool(tooltips=[("index", "@index"), ("club", "@club")])
plot.add_tools(node_hover_tool, BoxZoomTool(), ResetTool())

graph_renderer = from_networkx(G, nx.spring_layout, scale=1, center=(0, 0))

graph_renderer.node_renderer.glyph = Circle(size=15, fill_color=Spectral4[0])
graph_renderer.edge_renderer.glyph = MultiLine(line_color="edge_color", line_alpha=0.8, line_width=1)
plot.renderers.append(graph_renderer)

output_file("interactive_graphs.html")
show(plot)
票数 -1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/55826492

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档