Reputation: 1844
The error reported
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)
Code
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'}
where, 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()
When i pass the edge labels dictionary inside nx.draw_networkx_edge_labels using "labels" argument instead of "edge_labels", it shows empty dictionaries as shown in picture. But i am looking for edge labels with key:value entries.
Upvotes: 1
Views: 2124
Reputation: 1123710
The documentation for draw_networkx_edge_labels
states that the edge_labels
argument requires a dictionary where the keys are tuples with two elements:
edge_labels (dictionary) – Edge labels in a dictionary keyed by edge two-tuple of text labels (default=None). Only labels for the keys in the dictionary are drawn.
Your keys are single strings.
The tuples represent edges; in your graph those are tuples of integers, listed in map_paths_reduced
; your label keys must match those edges.
Upvotes: 1