我有代码
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)
plt.savefig("graph.png")
plt.show()
但是,我需要显示标签。 如何在图形的节点中显示数值和单词(一,二,三和四)?
答案 0 :(得分:18)
您只需要使用nx.Draw()调用 with_labels = True 参数:
>>> pandas.DataFrame(active_posts)
la life ny uk
0 18 9 84 4
1 6 18 27 3
您也可以调用font_size,font_color等
https://networkx.github.io/documentation/latest/reference/drawing.html