Statistics
| Branch: | Revision:

iof-tools / networkxMiCe / networkx-master / examples / drawing / plot_four_grids.py @ 5cef0f13

History | View | Annotate | Download (838 Bytes)

1
#!/usr/bin/env python
2
"""
3
==========
4
Four Grids
5
==========
6

7
Draw a graph with matplotlib.
8
You must have matplotlib for this to work.
9
"""
10
# Author: Aric Hagberg (hagberg@lanl.gov)
11

    
12
#    Copyright (C) 2004-2019
13
#    Aric Hagberg <hagberg@lanl.gov>
14
#    Dan Schult <dschult@colgate.edu>
15
#    Pieter Swart <swart@lanl.gov>
16
#    All rights reserved.
17
#    BSD license.
18

    
19
import matplotlib.pyplot as plt
20
import networkx as nx
21

    
22
G = nx.grid_2d_graph(4, 4)  # 4x4 grid
23

    
24
pos = nx.spring_layout(G, iterations=100)
25

    
26
plt.subplot(221)
27
nx.draw(G, pos, font_size=8)
28

    
29
plt.subplot(222)
30
nx.draw(G, pos, node_color='k', node_size=0, with_labels=False)
31

    
32
plt.subplot(223)
33
nx.draw(G, pos, node_color='g', node_size=250, with_labels=False, width=6)
34

    
35
plt.subplot(224)
36
H = G.to_directed()
37
nx.draw(H, pos, node_color='b', node_size=20, with_labels=False)
38

    
39
plt.show()