他们有可能在NetGraph中执行一些鼠标以进行节点突出显示?
基于 this 问题可以以这种方式生成一个使用NetGraph可视化的网络图:
import matplotlib.pyplot as plt
import networkx as nx
from netgraph import Graph # pip install netgraph
node_labels = {1: 'p→q', 2: '¬q', 3: '¬ (¬p)', 4: '¬p', 5: '¬p∧ ¬ (¬p)', 6: 'p', 7: 'q', 8: 'q∧ ¬q', 9: '¬p'}
color_map = {1: 'red', 2: 'red', 3: 'red', 4: 'red', 5: 'lightblue', 6: 'lightblue', 7: 'lightblue', 8: 'lightblue', 9: 'blue'}
edge_labels = {(3, 5): '∧I', (4, 5): '∧I', (4, 6): '¬E', (5, 6): '¬E', (1, 7): '→E', (6, 7): '→E', (2, 8): '∧I', (7, 8): '∧I', (8, 9): '¬E', (3, 9): '¬E'}
highlight = {1: {1}, 2: {2}, 3: {3}, 4: {4}, 5: {3, 4}, 6: {3}, 7: {1, 3}, 8: {1, 2, 3}, 9: {1, 2}}
graph = nx.from_edgelist(edge_labels, nx.DiGraph())
Graph(graph, node_layout='dot',
node_labels=node_labels, node_label_fontdict=dict(size=21),
edge_labels=edge_labels, edge_label_fontdict=dict(size=14), edge_label_rotate=False,
node_color=color_map, node_edge_color=color_map, arrows=True
)
plt.show()
我现在正在搜索一种简单的方法来突出显示鼠标上的节点。因此,我创建了字典的亮点。例如,它具有以下含义:
- 如果我是鼠标鼠标,则用索引
7
(q
),他们的 应突出显示节点1
(p→q
)和3
(¬(¬P)
) 与7
一起。
在NetGraph上,我找到了一些教程,交互式图形与节点及其继任者和前任有关的事情。但是在该教程中,尚不清楚突出显示的工作原理。
如果您能再次帮助我,我会很感激。谢谢你!
Based on this question it is possible to generate a networkx graph visualized with netgraph in this way:
import matplotlib.pyplot as plt
import networkx as nx
from netgraph import Graph # pip install netgraph
node_labels = {1: 'p→q', 2: '¬q', 3: '¬ (¬p)', 4: '¬p', 5: '¬p∧ ¬ (¬p)', 6: 'p', 7: 'q', 8: 'q∧ ¬q', 9: '¬p'}
color_map = {1: 'red', 2: 'red', 3: 'red', 4: 'red', 5: 'lightblue', 6: 'lightblue', 7: 'lightblue', 8: 'lightblue', 9: 'blue'}
edge_labels = {(3, 5): '∧I', (4, 5): '∧I', (4, 6): '¬E', (5, 6): '¬E', (1, 7): '→E', (6, 7): '→E', (2, 8): '∧I', (7, 8): '∧I', (8, 9): '¬E', (3, 9): '¬E'}
highlight = {1: {1}, 2: {2}, 3: {3}, 4: {4}, 5: {3, 4}, 6: {3}, 7: {1, 3}, 8: {1, 2, 3}, 9: {1, 2}}
graph = nx.from_edgelist(edge_labels, nx.DiGraph())
Graph(graph, node_layout='dot',
node_labels=node_labels, node_label_fontdict=dict(size=21),
edge_labels=edge_labels, edge_label_fontdict=dict(size=14), edge_label_rotate=False,
node_color=color_map, node_edge_color=color_map, arrows=True
)
plt.show()
I am now searching an easy way to highlight nodes on it on mouse over. So I created the dictionary highlight. By example it has the following sense:
- If I'm mouse over the node with index
7
(q
), their
should be highlighted the node1
(p→q
) and3
(¬ (¬p)
)
together with7
.
On netgraph I found some tutorials with interactive graphs which does similar things with the node and his successor and predecessor. But in that tutorial its not clear how exactly the highlighting works.
I would appreciate if you could help me again. Thank you!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如您指出的那样,
InteractiveGraph
类实现某些悬停事件,以便如果您将鼠标悬停在节点上,节点及其邻居以及它们之间的边缘以及它们之间的边缘将突出显示;如果悬停在边缘,则突出显示边缘及其源和目标节点。但是,NetGraph(尚未)不支持自定义悬停事件。但是,所需的功能并不难实施。
InteractiveGraph
从强调logic的节点和边缘突出显示逻辑
。将需要一些重大更改,这是目前实现图中其他元素的逻辑的地方。另外,
a>和
/a>需要一些较小的更改来支持其他关键字参数。如果您提出我的github上的问题或之后的一周。如果您想自己刺伤它,请始终欢迎拉动请求!
As you noted, the
InteractiveGraph
class implements certain hover events such that if you hover with the mouse over a node, the node and its neighbours as well as the edges between them are highlighted; if you hover over an edge, the edge and its source and target nodes are highlighted. However, custom hover events aren't supported in netgraph (yet).However, the desired feature would not be too hard to implement.
InteractiveGraph
inherits the node and edge highlighting logic fromEmphasizeOnHoverGraph
.EmphasizeOnHoverGraph._on_motion
would need some major changes, which is where the logic for highlighting other elements in the graph is implemented at the moment. Also,EmphasizeOnHoverGraph.__init__
andInteractiveGraph.__init__
would need some minor changes to support the additional keyword argument. If you raise an issue on my github, I won't forget to look into it next week or the week after. If you want to take a stab at it yourself, pull requests are always welcome!