0

I have this code to plot a visualization to a Djikstra Problem. I am having a bad time trying to print de node's label, like: A, B C, D... The graph and distances(weigths) are ok! I just need the node's label.

Can anyone help me?

import networkx as nx G = nx.read_edgelist("edges.txt", delimiter=",", data=[("weight", int)]) G.edges(data=True) edge_labels = dict( ((u, v), d["weight"]) for u, v, d in G.edges(data=True) ) pos = nx.random_layout(G) nx.draw(G, pos) nx.draw_networkx_edge_labels(G, pos, edge_labels=edge_labels) import matplotlib.pyplot as plt; plt.show() 
3
  • In the question, you say that you want node labels. But in the code you have edge labels. is it on purpose? Commented Sep 11, 2021 at 7:08
  • yes! i need them both. I read the docs but no success so far to print the node labels Commented Sep 11, 2021 at 7:15
  • does this work? stackoverflow.com/a/15549916/3896008 Commented Sep 11, 2021 at 7:18

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.