单击 pyvis.network // networkx 中的节点时如何设置其他边不可见?

How can I set other edges invisible when I click on a node in pyvis.network // networkx?

数据: 目前我正在一个相当大的网络上工作。因此,我发送了一部分节点和边缘的图片。

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')
 

我该怎么做才能创建这个?

如果我没理解错的话,你想在选择特定节点后隐藏某些边缘。我不太了解网络图像,但是我假设您需要单独添加某个 node A 或具有以下功能的节点列表:

由于 Pyvis 是在 Visjs 之上构建的,这些是网络下可用的 interaction-configurations:https://visjs.github.io/vis-network/docs/network/interaction.html

我看不到任何隐藏边缘选项。但是你可以使用这两个 -

"selectConnectedEdges"
*#Boolean   *true*  
#When true, on selecting a node, its connecting edges are highlighted.*

**hoverConnectedEdges** 
#Boolean    **true**    
#When true, on hovering over a node, it's connecting edges are highlighted

工作笔记本 - 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")