Statistics
| Branch: | Revision:

iof-tools / networkxMiCe / networkx-master / examples / basic / plot_read_write.py @ 5cef0f13

History | View | Annotate | Download (747 Bytes)

1
#!/usr/bin/env python
2
"""
3
======================
4
Read and write graphs.
5
======================
6

7
Read and write graphs.
8
"""
9
# Author: Aric Hagberg (hagberg@lanl.gov)
10

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

    
18
import sys
19

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

    
23
G = nx.grid_2d_graph(5, 5)  # 5x5 grid
24

    
25
# print the adjacency list
26
for line in nx.generate_adjlist(G):
27
    print(line)
28
# write edgelist to grid.edgelist
29
nx.write_edgelist(G, path="grid.edgelist", delimiter=":")
30
# read edgelist from grid.edgelist
31
H = nx.read_edgelist(path="grid.edgelist", delimiter=":")
32

    
33
nx.draw(H)
34
plt.show()