[英]Python networkx - How to draw graph with labels
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)
所以目前我使用最新的.networkx。 当我使用 nx.draw(G, with_values=True) 时,它使用顶点索引而不是标签。
我怎样才能解决这个问题? 谢谢你。
更改此命令: nx.draw(G,with_labels=True)
到nx.draw(G,with_labels=True, labels = myLabels)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.