January 2018
Beginner to intermediate
548 pages
12h 11m
English
In this recipe, we will show how to create, manipulate, and visualize graphs with NetworkX.
NetworkX is installed by default in Anaconda. If needed, you can also install it manually with conda install networkx.
>>> import numpy as np
import networkx as nx
import matplotlib.pyplot as plt
%matplotlib inline>>> n = 10 # Number of nodes in the graph.
# Each node is connected to the two next nodes,
# in a circular fashion.
adj = [(i, (i + 1) % n) for i in range(n)]
adj += [(i, (i + 2) % n) for i in range(n)]Graph object ...Read now
Unlock full access