Single Source Shortest Path: length = nx.single_source_shortest_path_length(g1, 0) for node in length: print(f"{node}: {length[node]}") A Matrix to Image: Graph and Networkx Tutorials