def DrawGraph(B): l, r = nx.bipartite.sets(B) pos = {} # Update position for node from each group pos.update((node, (1, index)) for index, node in enumerate(l)) pos.update((node, (2, index)) for index, node in enumerate(r)) nx.draw(B, pos, with_labels = True) #with_labels=true is to show the node number in the output graph edge_labels = dict([((u, v), d['length']) for u, v, d in B.edges(data = True)]) nx.draw_networkx_edge_labels(B, pos, edge_labels = edge_labels, label_pos = 0.2, font_size = 11) #prints weight on all the edges return pos #main function if __name__ == "__main__": B, cost = CreateGraph(); pos = DrawGraph(B) hungarian(B, pos, cost) plt.show()