3.4. NetworkX and PyVis#
import networkx as nx
Just as we did in the previous section, we will create a NetworkX
nx.Graph() and populate it with our relationships.
G = nx.Graph() rels = [ ["Fred", "George"], ["Harry", "Rita"], ["Fred", "Ginny"], ["Tom", "Ginny"], ["Harry", "Ginny"], ["Harry", "George"], ["Frank", "Ginny"], ["Marge", "Rita"], ["Fred", "Rita"] ] G.add_edges_from(rels)
Now that we have our NetworkX Graph, we can create a PyVis
net = Network()
from_nx() method, which will take a single argument, our NetworkX
With the data now populated, we can save and view our PyVis
Notice that our graph is rendered precisely just as it had been with NetworkX and Matplotlib, but now that same data is dynamic. In other words, we were able to leverage the best of NetworkX and PyVis with this approach.