In [194]:
    
import matplotlib.pyplot as plt
%matplotlib inline
    
In [195]:
    
import nltk
from nltk.book import text6
    
In [196]:
    
#get a collection of words from text6 that both words and whose length is greater than 11
col = list(set([w.upper() for w in text6 if w.isalpha() and len(w)>11]))
col
    
    Out[196]:
In [197]:
    
import networkx as nx
G=nx.Graph()
#We use the words from above as the nodes on the graph
G.add_nodes_from(col)
    
In [198]:
    
#add an edge between the second and third entry
G.add_edge(col[1],col[2])
    
In [199]:
    
#add an edge between the first entry and all even-length entries in the collection of words.
for i in range(0,len(col)):
    if len(col[i])%2 ==0:
        G.add_edge(col[0],col[i])
    
In [200]:
    
nx.draw_networkx(G)
    
    
In [201]:
    
G.edges()
    
    Out[201]:
A Look at the sample Florentine Family Graph
In [202]:
    
nx.draw_networkx(nx.florentine_families_graph())
    
    
In [203]:
    
nx.florentine_families_graph().edges()
    
    Out[203]:
In [204]:
    
#We can see each family and its connections.
flo = nx.florentine_families_graph()
for i in range(1, len(flo.nodes())):
    print str(flo.nodes()[i]) + " --- " + str(flo.neighbors(flo.nodes()[i]))
    
    
In [ ]: