您只需要使用调用with_labels=True
参数nx.Draw()
:
import networkx as nx
import matplotlib.pyplot as plt
G = nx.DiGraph()
G.add_nodes_from([1, 2, 3, 4])
G.add_edges_from([(1, 2), (2, 1), (2, 3)])
nx.draw(G,with_labels=True)
plt.savefig("graph.png")
plt.show()
您也可以拨打font_size
,font_color
等等。
请参阅此处的文档:https : //networkx.github.io/documentation/latest/reference/drawing.html
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句