import networkx as nx import matplotlib.pyplot as plt G = nx.DiGraph() #creates a 'directed' graph; nx.Graph() creates an undirected graph G.add_node(1) G.add_node(2) G.add_node(3) G.add_node(4) G.add_node(5) G.add_node(6) G.add_edge(1,2) G.add_edge(1,3) G.add_edge(1,5) G.add_edge(4,5) G.add_edge(6,5) print G.nodes(), G.edges() # Plotting option 1 - using nx.draw_circular() # Nodes 1 and 5 and the edge running between them are painted with distinct colors. plt.figure(figsize=(8,8)) nx.draw_circular(G,node_size=500,with_labels=True) #creates a circular graph. Refer http://networkx.lanl.gov/tutorial/tutorial.html#drawing-graphs nx.draw_circular(G,node_size=500,nodelist=[1,5],edgelist=[(1,5)],node_color='b',edge_color='g',width=3) plt.axis('equal') #plt.savefig('circular_graph.png') plt.show() # Plotting option 2 - using graphviz_layout() pos=nx.graphviz_layout(G,prog='circo',args='') #'circo creates circular graph #for other 'prog' options refer to http://www.graphviz.org/Documentation.php (see 'Layout Commands') plt.figure(figsize=(8,8)) nx.draw(G,pos,node_size=20,alpha=0.5,node_color="blue", with_labels=False) plt.axis('equal') #plt.savefig('circular_graph.png') plt.show()