In [32]:
%matplotlib inline
import networkx as nx
import pylab as p

In [70]:
class Node:
    def __init__(self, x):
        self.data  = x
        self.parent = None
        self.child = None

def insert(node, x):
    node.child = Node(x)
    return node

In [77]:
node = Node(1)
node = insert(node, 3)
node.child.parent = node
node = node.child
node = insert(node, 10)
node.child.parent = node
node = node.child

In [80]:
print node.data
print node.parent.data
print node.parent.parent.data


10
3
1

In [89]:
g = nx.Graph(
{"mumori" : ["kotrip", "barihu", "rosa", "yadon"],
 "kotrip" : ["tanaka", "suzuki", "yamada"],
 "tanaka" : ["taro", "saburo"]
 }
)

In [90]:
nx.draw(g)



In [91]:
pos = networkx.spring_layout(g)

p.figure(figsize=(10, 10)) 

font_path = "/usr/share/fonts/japanese/TrueType/sazanami-gothic.ttf"
font_prop = font_manager.FontProperties(fname=font_path)

networkx.draw_networkx_nodes(g, pos, node_size=3000, node_color="w")
networkx.draw_networkx_edges(g, pos, width=3)
networkx.draw_networkx_labels(g, pos, font_size=16)


Out[91]:
{'barihu': <matplotlib.text.Text at 0x10fd2a1d0>,
 'kotrip': <matplotlib.text.Text at 0x10fd1ed50>,
 'mumori': <matplotlib.text.Text at 0x10fd35310>,
 'rosa': <matplotlib.text.Text at 0x10fd2aa50>,
 'saburo': <matplotlib.text.Text at 0x10fd2ae90>,
 'suzuki': <matplotlib.text.Text at 0x10fd35b90>,
 'tanaka': <matplotlib.text.Text at 0x10fd35750>,
 'taro': <matplotlib.text.Text at 0x10fd1e910>,
 'yadon': <matplotlib.text.Text at 0x10fd2a610>,
 'yamada': <matplotlib.text.Text at 0x104b42250>}

In [87]:
g = nx.Graph(
{"mumori" : ["kotrip", "barihu"],
 "rosa"   : ["yadon", "kotrip"],
 "yadon"  : ["rosa", "barihu"],
 "kotrip" : ["mumori", "rosa"],
 "barihu" : ["mumori", "yadon"]
 }
)