In [1]:
import networkx as nx
%matplotlib inline
In [2]:
G=nx.Graph()
In [3]:
G.nodes()
Out[3]:
In [4]:
G.edges()
Out[4]:
In [5]:
G.add_node(1)
In [6]:
G.nodes()
Out[6]:
In [7]:
G.add_nodes_from([5,6,7])
In [8]:
G.add_edge(7,1)
In [9]:
nx.draw(G)
In [10]:
G.add_edges_from([(6,7),(1,5)])
In [11]:
nx.draw(G)
In [12]:
for n in G.nodes_iter():
print(n)
In [13]:
for u,v in G.edges_iter():
print(u,v)
In [14]:
G[1] #All dictionaries
Out[14]:
In [15]:
G[5]
Out[15]:
In [16]:
[n for n in G[1]]
Out[16]:
In [17]:
G.neighbors(1)
Out[17]:
In [18]:
G.number_of_nodes()
Out[18]:
In [19]:
G.number_of_edges()
Out[19]:
In [20]:
nx.diameter(G)
Out[20]:
In [21]:
nx.radius(G)
Out[21]: