报告错误
Python3.5.2\lib\site-packages\networkx\drawing\nx_pylab.py",
line 836, in draw_networkx_edge_labels for (n1, n2), label in labels.items():
ValueError: not enough values to unpack (expected 2, got 1)
码
map_paths_reduced = [(0, 75), (75, 38), (38, 86), (86, 119), (119, 85), (85, 44), (44, 65), (65, 127), (127, 106), (106, 31)]
edge_labels_dict_reduced = {'7': '27.0', '4': '31.0', '2': '17.0', '0': '12.0', '6': '13.0', '1': '16.0', '8': '8.0', '9': '34.0', '3': '6.0', '5': '45.0'}
其中,len(edge_labels)= 150
G = nx.DiGraph()
G.add_nodes_from(range(len(edge_labels)+1))
black_edges = [edge for edge in G.edges()]
pos = nx.random_layout(G)
G.add_edges_from(map_paths_reduced)
nx.draw_networkx_nodes(G, pos, cmap=plt.get_cmap('jet'), node_size=100)
nx.draw_networkx_labels(G, pos, font_size=1)
nx.draw_networkx_edges(G, pos, edgelist=black_edges, arrows=True)
nx.draw_networkx_edge_labels(G, pos, edge_labels=edge_labels_dict_reduced) ##ERROR REPORTED HERE
nx.draw_networkx(G, pos, arrows=True)
return plt.show()
当我使用“labels”参数而不是“edge_labels”在nx.draw_networkx_edge_labels中传递边标签字典时,它会显示如图所示的空字典。但我正在寻找带键:值条目的边缘标签。