Statistics
| Branch: | Revision:

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

History | View | Annotate | Download (1.42 KB)

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

7
Sampson's monastery data.
8

9
Shows how to read data from a zip file and plot multiple frames.
10

11
"""
12
# Author: Aric Hagberg (hagberg@lanl.gov)
13

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

    
21
import zipfile
22
try:
23
    from cStringIO import StringIO
24
except ImportError:
25
    from io import BytesIO as StringIO
26

    
27
import matplotlib.pyplot as plt
28
import networkx as nx
29

    
30
zf = zipfile.ZipFile('sampson_data.zip')  # zipfile object
31
e1 = StringIO(zf.read('samplike1.txt'))  # read info file
32
e2 = StringIO(zf.read('samplike2.txt'))  # read info file
33
e3 = StringIO(zf.read('samplike3.txt'))  # read info file
34
G1 = nx.read_edgelist(e1, delimiter='\t')
35
G2 = nx.read_edgelist(e2, delimiter='\t')
36
G3 = nx.read_edgelist(e3, delimiter='\t')
37
pos = nx.spring_layout(G3, iterations=100)
38
plt.clf()
39

    
40
plt.subplot(221)
41
plt.title('samplike1')
42
nx.draw(G1, pos, node_size=50, with_labels=False)
43
plt.subplot(222)
44
plt.title('samplike2')
45
nx.draw(G2, pos, node_size=50, with_labels=False)
46
plt.subplot(223)
47
plt.title('samplike3')
48
nx.draw(G3, pos, node_size=50, with_labels=False)
49
plt.subplot(224)
50
plt.title('samplike1,2,3')
51
nx.draw(G3, pos, edgelist=list(G3.edges()), node_size=50, with_labels=False)
52
nx.draw_networkx_edges(G1, pos, alpha=0.25)
53
nx.draw_networkx_edges(G2, pos, alpha=0.25)
54
plt.show()