本文整理汇总了Python中networkx.read_multiline_adjlist函数的典型用法代码示例。如果您正苦于以下问题:Python read_multiline_adjlist函数的具体用法?Python read_multiline_adjlist怎么用?Python read_multiline_adjlist使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了read_multiline_adjlist函数的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_multiline_adjlist_integers
def test_multiline_adjlist_integers(self):
(fd, fname) = tempfile.mkstemp()
G = nx.convert_node_labels_to_integers(self.G)
nx.write_multiline_adjlist(G, fname)
H = nx.read_multiline_adjlist(fname, nodetype=int)
H2 = nx.read_multiline_adjlist(fname, nodetype=int)
assert_nodes_equal(list(H), list(G))
assert_edges_equal(list(H.edges()), list(G.edges()))
os.close(fd)
os.unlink(fname)
示例2: test_multiline_adjlist_digraph
def test_multiline_adjlist_digraph(self):
G = self.DG
(fd, fname) = tempfile.mkstemp()
nx.write_multiline_adjlist(G, fname)
H = nx.read_multiline_adjlist(fname, create_using=nx.DiGraph())
H2 = nx.read_multiline_adjlist(fname, create_using=nx.DiGraph())
assert_not_equal(H, H2) # they should be different graphs
assert_nodes_equal(list(H), list(G))
assert_edges_equal(list(H.edges()), list(G.edges()))
os.close(fd)
os.unlink(fname)
示例3: test_multiline_adjlist_graph
def test_multiline_adjlist_graph(self):
G=self.G
(fd,fname)=tempfile.mkstemp()
nx.write_multiline_adjlist(G,fname)
H=nx.read_multiline_adjlist(fname)
H2=nx.read_multiline_adjlist(fname)
assert_not_equal(H,H2) # they should be different graphs
assert_equal(sorted(H.nodes()),sorted(G.nodes()))
assert_equal(sorted(H.edges()),sorted(G.edges()))
os.close(fd)
os.unlink(fname)
示例4: test_multiline_adjlist_delimiter
def test_multiline_adjlist_delimiter(self):
fh = io.BytesIO()
G = nx.path_graph(3)
nx.write_multiline_adjlist(G, fh, delimiter=':')
fh.seek(0)
H = nx.read_multiline_adjlist(fh, nodetype=int, delimiter=':')
assert_nodes_equal(list(H), list(G))
assert_edges_equal(list(H.edges()), list(G.edges()))
示例5: test_read_multiline_adjlist_1
def test_read_multiline_adjlist_1(self):
# Unit test for https://networkx.lanl.gov/trac/ticket/252
s = b"""# comment line
1 2
# comment line
2
3
"""
bytesIO = io.BytesIO(s)
G = nx.read_multiline_adjlist(bytesIO)
adj = {'1': {'3': {}, '2': {}}, '3': {'1': {}}, '2': {'1': {}}}
assert_graphs_equal(G, nx.Graph(adj))
示例6: test_unicode
def test_unicode(self):
G = nx.Graph()
try: # Python 3.x
name1 = chr(2344) + chr(123) + chr(6543)
name2 = chr(5543) + chr(1543) + chr(324)
except ValueError: # Python 2.6+
name1 = unichr(2344) + unichr(123) + unichr(6543)
name2 = unichr(5543) + unichr(1543) + unichr(324)
G.add_edge(name1, 'Radiohead', **{name2: 3})
fd, fname = tempfile.mkstemp()
nx.write_multiline_adjlist(G, fname)
H = nx.read_multiline_adjlist(fname)
assert_graphs_equal(G, H)
os.close(fd)
os.unlink(fname)
示例7: test_read_multiline_adjlist_1
def test_read_multiline_adjlist_1():
# Unit test for https://networkx.lanl.gov/trac/ticket/252
s = """# comment line
1 2
# comment line
2
3
"""
import StringIO
strIO = StringIO.StringIO(s)
G = nx.read_multiline_adjlist(strIO)
adj = {'1': {'3': {}, '2': {}}, '3': {'1': {}}, '2': {'1': {}}}
assert_equal(G.adj, adj)
示例8: test_latin1
def test_latin1(self):
G = nx.Graph()
try: # Python 3.x
blurb = chr(1245) # just to trigger the exception
name1 = 'Bj' + chr(246) + 'rk'
name2 = chr(220) + 'ber'
except ValueError: # Python 2.6+
name1 = 'Bj' + unichr(246) + 'rk'
name2 = unichr(220) + 'ber'
G.add_edge(name1, 'Radiohead', **{name2: 3})
fd, fname = tempfile.mkstemp()
nx.write_multiline_adjlist(G, fname, encoding='latin-1')
H = nx.read_multiline_adjlist(fname, encoding='latin-1')
assert_graphs_equal(G, H)
os.close(fd)
os.unlink(fname)
示例9: test_latin1
def test_latin1(self):
G = nx.Graph()
try: # Python 3.x
blurb = chr(1245) # just to trigger the exception
name1 = "Bj" + chr(246) + "rk"
name2 = chr(220) + "ber"
except ValueError: # Python 2.6+
name1 = "Bj" + unichr(246) + "rk"
name2 = unichr(220) + "ber"
G.add_edge(name1, "Radiohead", {name2: 3})
fd, fname = tempfile.mkstemp()
nx.write_multiline_adjlist(G, fname, encoding="latin-1")
H = nx.read_multiline_adjlist(fname, encoding="latin-1")
assert_graphs_equal(G, H)
os.close(fd)
os.unlink(fname)
示例10: read_graph
def read_graph(from_user, to_user):
try:
with get_file(edgelist_fname(**locals()), 'r') as fd:
return NX.read_multiline_adjlist(fd, delimiter='\t')
except IOError:
return None
示例11: open
G.add_edge(hd, mh)
G.add_edge(mc, st)
G.add_edge(boc, mc)
G.add_edge(boc, dt)
G.add_edge(st, dt)
G.add_edge(q, st)
G.add_edge(dt, mh)
G.add_edge(st, mh)
# write in UTF-8 encoding
fh = open('edgelist.utf-8', 'wb')
fh.write('# -*- coding: utf-8 -*-\n'.encode('utf-8')) # encoding hint for emacs
nx.write_multiline_adjlist(G, fh, delimiter='\t', encoding='utf-8')
# read and store in UTF-8
fh = open('edgelist.utf-8', 'rb')
H = nx.read_multiline_adjlist(fh, delimiter='\t', encoding='utf-8')
for n in G.nodes():
if n not in H:
print(False)
print(list(G.nodes()))
pos = nx.spring_layout(G)
nx.draw(G, pos, font_size=16, with_labels=False)
for p in pos: # raise text positions
pos[p][1] += 0.07
nx.draw_networkx_labels(G, pos)
plt.show()