Search code examples
pythonnetworkinggraphnetworkxpyvis

Operations on a graph using pyvis with python


I have defined a graph by using from pyvis.network import Network and defining a network as net = Network().

I added to the net edges and nodes using the functions net.add_nodes(nodes) and net.add_edge(x, y). There is any chance to deal with this graph not only using a visualization? So for e.g. to find all paths between two specific nodes? Because searching in the documentation there is only the possibility to plot the graph. I saw other options (e.g. class) to deal with graphs (example) but is very annoying to define the graph with a dict of a dict.


Solution

  • From the pyvis documentation:

    The pyvis library is meant for quick generation of visual network graphs with minimal python code. It is designed as a wrapper around the popular Javascript visJS library found at this link.

    You probably want a library such as networkx, which you probably have tagged by accident. It's description states

    NetworkX is a Python package for the creation, manipulation, and study of the structure, dynamics, and functions of complex networks.

    This includes many operations, see the tutorial or to take your example: shortest path