0
votes
from graphviz import *
import networkx as nx
from networkx import *
import matplotlib.pyplot as plt

    G = nx.DiGraph()
    G.add_node(1)
    G.add_node(2)
    G.add_edge(1,2)
    myLabels = {1: 'node1', 2: 'node2'}
    nx.set_node_attributes(G, myLabels, 'label')
    nx.draw(G,with_labels=True)

So current I use the latest networkx. When I use nx.draw(G, with_values=True), it uses the vertex indexes instead of labels.

How can I fix this? Thank you.

Image should say node1, node2

1
Look at the second half of this answer: stackoverflow.com/a/28533293/2966723 - Joel

1 Answers

1
votes

Change this command: nx.draw(G,with_labels=True) to nx.draw(G,with_labels=True, labels = myLabels)