import networkx as nx
%matplotlib inline

G=nx.Graph()

G.nodes()

G.edges()

G.add_node(1)

G.nodes()

G.add_nodes_from([5,6,7])

G.add_edge(7,1)

nx.draw(G)

G.add_edges_from([(6,7),(1,5)])

nx.draw(G)

"""
Explanation: Introduction to NetworkX
Some Key Featuress

A python library for creating, analyzing and visualizing graphs
Easy to use
Excellent documentation
Free software

Creating graphs
End of explanation
"""


for n in G.nodes_iter():
    print(n)

"""
Explanation: Accessing graph elements
Looping over nodes
End of explanation
"""


for u,v in G.edges_iter():
    print(u,v)

"""
Explanation: Looping over edges
End of explanation
"""


G[1]    #All dictionaries

G[5]

"""
Explanation: Looping over neighbourhood of a node
End of explanation
"""


[n for n in G[1]]

G.neighbors(1)

"""
Explanation: So it's really easy to loop over the whole graph or the neighbourhood of a node
End of explanation
"""


G.number_of_nodes()

G.number_of_edges()

nx.diameter(G)

nx.radius(G)

"""
Explanation: Accessing global graph properties
End of explanation
"""


