擅长:python、mysql、java
<p>从<a href="https://networkx.github.io/documentation/latest/reference/generated/networkx.drawing.nx_pylab.draw_networkx.html" rel="nofollow">documentation</a>:</p>
<blockquote>
<p>Node color. Can be a single color format string, or a sequence of colors with the same length as nodelist. If numeric values are specified they will be mapped to colors using the cmap and vmin,vmax parameters. See matplotlib.scatter for more details.</p>
</blockquote>
<p><code>part = community.best_partition(G)</code>为每个节点分配一个社区-<code>part</code>是一个dict,而<code>part[node]</code>是该节点所属的社区(每个都分配了一个整数)。稍后<code>values = [part.get(node) for node in G.nodes()]</code>按照节点在<code>G.nodes()</code>中出现的顺序为每个节点创建一个带有社区号的列表。</p>
<p>然后在plotting命令中,它将使用这些社区编号来确定节点的颜色。分配给同一社区的所有节点都将具有相同的颜色。</p>
<p>节点的物理位置由spring布局指定。您可以看到,spring布局似乎将节点放置在了一个位置上,该位置表示一些与<code>community.best_partition</code>所发现的社区不同的社区。这也许有点令人惊讶,但肯定没有什么能阻止它。它确实让我认为你使用的算法并不能恰当地解释网络中的所有结构。<code>best_partition</code>的<a href="http://perso.crans.org/aynaud/communities/api.html#community.best_partition" rel="nofollow">documentation</a>给出了底层算法的一些解释。</p>