[英]How can I set other edges invisible when I click on a node in pyvis.network // networkx?
Data: Currently I am working on a quite big.network.数据:目前我在一个相当大的网络上工作。 Therefore I am sending a picture of a part of nodes and edges.
因此,我发送了一部分节点和边缘的图片。
pos = nx.nx_agraph.graphviz_layout(G, prog="twopi")
Xs=[a[0] for a in pos.values()]
Ys=[a[1] for a in pos.values()]
from pyvis.network import Network
g=Network(height=2000,width=2000,directed=True)
g.from_nx(G)
g.add_nodes(Nodes,x=Xs,y=Ys)
g.barnes_hut(gravity=-80000,central_gravity=0.5,spring_length=150,spring_strength=0.001,damping=0.09,overlap=0)
g.show('nx.html')
What can I do to create this?我能做些什么来创建这个?
If I can understand correctly, you want to hide certain edges after selection of particular node.如果我能理解正确的话,你想在选择特定节点后隐藏某些边缘。 I do not quite understand the.network image, however I am assuming there is a certain node A that you need to add separately or a list of nodes with the functionality:
我不太了解 .network 图像,但是我假设您需要单独添加某个节点 A或具有以下功能的节点列表:
Since Pyvis is build on top of Visjs these are the interaction-configurations available under the.network: https://visjs.github.io/vis.network/docs.network/interaction.html由于 Pyvis 是建立在 Visjs 之上的,因此这些是.network 下可用的交互配置: https://visjs.github.io/vis.network/docs.network/interaction.html
I cannot see any hide edges option.我看不到任何隐藏边缘选项。 However you can use these two -
但是你可以使用这两个 -
"selectConnectedEdges"
*#Boolean *true*
#When true, on selecting a node, its connecting edges are highlighted.*
OR或者
**hoverConnectedEdges**
#Boolean **true**
#When true, on hovering over a node, it's connecting edges are highlighted
Working notebook - https://colab.research.google.com/drive/1S3zpSotmAhwx_8Qo81vvTk_egpNpStPu?usp=sharing工作笔记本 - https://colab.research.google.com/drive/1S3zpSotmAhwx_8Qo81vvTk_egpNpStPu?usp=sharing
#!pip install pyvis
import pyvis
from pyvis import network
from pyvis.network import Network
G = Network(height='400px', width='80%', bgcolor='white', notebook=True,
font_color ='black')
G.add_node(1)
G.add_node(2)
G.add_node(3)
G.add_edges([(1,2,4),(1,3,2),(2,3,6)])
options = {
"nodes":{
"font":{
"size": 50,
"bold":True
}
},
"edges":{
"color":'red',
"smooth":False
},
"physics":{
"barnesHut":{
"gravitationalConstant":-500000,
"centralGravity":12,
"springLength": 50,
"springConstant": 0.7,
"damping": 3,
"avoidOverlap": 10
}
},
"interaction":{
"selectConnectedEdges": True
}}
G.options=options
G.show('sample.html')
import IPython
IPython.display.HTML(filename= r"/content/sample.html")
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.