擅长:python、mysql、java
<p><a href="https://i.stack.imgur.com/0AyxF.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/0AyxF.png" alt="enter image description here"/></a>检查<a href="https://networkx.github.io/documentation/latest/_modules/networkx/drawing/nx_pylab.html#draw" rel="nofollow noreferrer">nx.draw source code</a>或{a3}。我不太确定我是否正确地回答了您的问题,因为根据我的理解,这是一个相当直接的问题,您可以简单地为图添加标签,如下所示:</p>
<pre><code>networkx.draw(graph, node_positions, with_labels = True)
</code></pre>
<p>也可以直接使用<a href="https://networkx.github.io/documentation/latest/reference/generated/networkx.drawing.nx_pylab.draw_spring.html" rel="nofollow noreferrer">draw_spring</a>,而不必明确指定节点位置:</p>
^{pr2}$
<p>此图显示运行以下代码的结果:</p>
<pre><code>import networkx as nx
G = nx.erdos_renyi_graph(10,0.4)
nx.draw(G, with_labels=True)
plt.show()
</code></pre>