试图绘制类似树的分层结构,但是当分支导致公共输出时会出错。
在绘制具有不同输出的层次树时没有出现错误,但是当公共输出时发生错误。
def Create_Hierarchy(chunks):
G = nx.Graph()
G.add_edges_from(chunks)
pos = _hierarchy_pos(G, root='A', width=0.07, vert_gap=0.02, vert_loc=0.09, xcenter=0.50)
nx.draw(G, pos, arrows=True, with_labels=True)
plt.subplots_adjust(top=0.9, wspace=4.0, hspace=2.99)
plt.savefig('D:\\Hierarchy'+timestr+'.png')
plt.show()
# return rootTree
print(Create_Hierarchy(chunks=[('A','B'), ('A','C'), ('A','D'), ('A','E'), ('A','F'), (**'B','G'**), (**'C','G'**), ('D','I'), ('E','J'), ('F','K')]))
错误:
File "D:\Selenium Workspace\PyDemoProject\src\Tree.py", line 67, in _hierarchy_pos
pos = _hierarchy_pos(G, child, width=dx, vert_gap=vert_gap, vert_loc=vert_loc-vert_gap, xcenter=nextx, pos=pos, parent=root)
File "D:\Selenium Workspace\PyDemoProject\src\Tree.py", line 67, in _hierarchy_pos
pos = _hierarchy_pos(G, child, width=dx, vert_gap=vert_gap, vert_loc=vert_loc-vert_gap, xcenter=nextx, pos=pos, parent=root)
File "D:\Selenium Workspace\PyDemoProject\src\Tree.py", line 67, in _hierarchy_pos
pos = _hierarchy_pos(G, child, width=dx, vert_gap=vert_gap, vert_loc=vert_loc-vert_gap, xcenter=nextx, pos=pos, parent=root)
[Previous line repeated 995 more times]
File "D:\Selenium Workspace\PyDemoProject\src\Tree.py", line 59, in _hierarchy_pos
children = list(G.neighbors(root))
File "C:\Users\VG-11\AppData\Roaming\Python\Python37\site-packages\networkx\classes\graph.py", line 1266, in neighbors
return iter(self._adj[n])