Skip to content

Commit

Permalink
Merge branch 'develop' of https://github.com/jzsmoreno/likelihood int…
Browse files Browse the repository at this point in the history
…o develop
  • Loading branch information
jzsmoreno committed Apr 11, 2024
2 parents c1997c0 + 22952cd commit bbc214a
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions likelihood/graph/graph.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import networkx as nx
from IPython.display import HTML, display
from pandas.core.frame import DataFrame
from pyvis.network import Network
Expand Down Expand Up @@ -48,3 +49,21 @@ def draw(self, name="graph.html", **kwargs) -> None:

html_file_content = open(name, "r").read()
display(HTML(html_file_content))

def pyvis_to_networkx(self):
nx_graph = nx.Graph()

# Añadimos nodos
for node_dic in self.G.nodes:
id = node_dic["id"]
del node_dic["id"]
nx_graph.add_nodes_from([(id, node_dic)])

# Añadimos aristas
for edge in self.G.edges:
source, target = edge["from"], edge["to"]
del edge["from"]
del edge["to"]
nx_graph.add_edges_from([(source, target, edge)])

return nx_graph

0 comments on commit bbc214a

Please sign in to comment.