简体   繁体   English

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

[英]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 I am trying to do is setting other edges invisible when I click on a node.我想要做的是在单击节点时将其他边缘设置为不可见。 For example, if I click on 'node A', I just want to see just the node A's edges.*例如,如果我点击“节点 A”,我只想看到节点 A 的边缘。*

在此处输入图像描述

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

例子 Here is a sample code这是一个示例代码

#!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.

相关问题 如何禁用 pyvis.network 图中的权重 - How to disable weights in pyvis.network graph 如何为networkx边缘添加权重? - how can i add weight to networkx edges? 如何使用NetworkX实现“弱”边缘? - How can I implement “weak” edges with NetworkX? 在networkx中工作的边缘宽度,但在pyvis中没有 - Width of edges working in networkx, but not in pyvis pyvis 库如何使用 function nt.from_nx 转换我已经从 Networkx 获得的网络图 - pyvis Library how to convert a network graph that i all ready have from Networkx using the function nt.from_nx 如何让用户删除 PyVis 网络图中的节点或边? - How do I let a user delete a node or edge in a PyVis network graph? 使用 networkx 绘制图形时,如何在边上使用颜色? - When plotting graphs using networkx, how can I use colors on edges? 在networkx图中,如何找到没有出边的节点? - In a networkx graph, how can I find nodes with no outgoing edges? NetworkX,当节点不在图中时,如何成功捕获network.exception.NetworkXError? - NetworkX, How do I successfully catch network.exception.NetworkXError when node is not in the graph? 如何使用networkx绘制图形网络并询问Python中父节点和子节点之间是否应该存在连接? - How can I draw graphs network using networkx and asking if there should be connection between a parent and child node in Python?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM