我试图在网络x中为边缘添加边缘标签。我将使用nx.write_dot()
将其转换为点文件。我怎样才能做到这一点?当我这样做时:G.add_edge("ATC", "TCG", label = "ATCG")
,nx.write_dot()
会抛出错误。我喜欢networkx,但如果它不能标记边缘,那么我认为我必须使用另一个库。
具体来说,我收到了这个错误:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python3.3/site-packages/networkx/drawing/nx_agraph.py", line 180, in write_dot
A.clear()
File "/usr/local/lib/python3.3/site-packages/pygraphviz/agraph.py", line 907, in clear
self.edge_attr.clear()
File "/usr/local/Cellar/python3/3.3.3/Frameworks/Python.framework/Versions/3.3/lib/python3.3/collections/abc.py", line 553, in clear
self.popitem()
File "/usr/local/Cellar/python3/3.3.3/Frameworks/Python.framework/Versions/3.3/lib/python3.3/collections/abc.py", line 542, in popitem
key = next(iter(self))
File "/usr/local/lib/python3.3/site-packages/pygraphviz/agraph.py", line 1692, in __iter__
for (k,v) in self.iteritems():
File "/usr/local/lib/python3.3/site-packages/pygraphviz/agraph.py", line 1700, in iteritems
yield (gv.agattrname(ah).decode(self.encoding),
AttributeError: 'str' object has no attribute 'decode'
答案 0 :(得分:1)
应该是这样的:
In [1]: import networkx as nx
In [2]: G = nx.Graph()
In [3]: G.add_edge(1,2,label='one-two')
In [4]: import sys
In [5]: nx.write_dot(G,sys.stdout)
strict graph {
1 -- 2 [label="one-two"];
}