Untitled
unknown
python
a year ago
563 B
10
Indexable
def show_cost_mat_path(path): G = nx.DiGraph() for i in range(len(path) - 1): u, v = path[i], path[i + 1] G.add_edge(u, v, weight=COST_MATRIX[u, v]) pos = nx.spring_layout(G) plt.figure(figsize=(12, 8)) nx.draw(G, pos, with_labels=True, node_color='lightblue', node_size=500, font_size=10, font_weight='bold', arrowsize=20) edge_labels = {(u, v): f'{G[u][v]["weight"]}' for u, v in G.edges()} nx.draw_networkx_edge_labels(G, pos, edge_labels=edge_labels, font_color='red') plt.title('Cost path') plt.show()
Editor is loading...
Leave a Comment