title: Choose the number of clusters and vertices in python igraph
body: <p>I have a <strong>complete weighted graph</strong> as you can see in the image below:</p>
  <p><a href="https://i.stack.imgur.com/LnFOF.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/LnFOF.png" alt="enter image description here" /></a></p>
  <p><strong>The Goal:</strong>
  My goal is to be able to choose the number of clusters and the number of vertices in each cluster using python's implementation of iGraph</p>
  <p><strong>What I've Tried So Far:</strong></p>
  <pre><code>import igraph
  import cairo
  import numpy as np
  
  # Import data (see below, I've included this file)
  graph2 = igraph.Graph.Read_Ncol('10_graph.ncol')
  
  # Assigns weights to weights1
  weights1 = graph2.es[&quot;weight&quot;]
  
  # Converts it to undirected graph
  graph2.to_undirected()
  
  # 'graph2.to_undirected()' strips the graph of its weights
  # so we restore them to the &quot;weight&quot; attribute after
  graph2.es[&quot;weight&quot;] = weights1
  
  # Reduces the number of significant figures in each edge label
  graph2.es[&quot;label&quot;] = np.around(weights1, 2)
  
  # Label all the vertices
  graph2.vs[&quot;label&quot;] = range(1, 11)
  
  # Things I've tried: (uncomment only one at a time)
  # Both return non-clustered graphs.
  #community = graph2.community_spinglass(weights1)
  community = graph2.community_leading_eigenvector(weights=graph2.es[&quot;weight&quot;], clusters=3)
  igraph.plot(community)
  </code></pre>
  <p>If the above code is run, you get as output the above image. You get the same image for both community-finding algorithms I've included. I've commented out one of them, so if you want to use the other one, go ahead and uncomment <code>#community = graph2.community_spinglass(weights1)</code>.</p>
  <p><strong>The Problem(s):</strong></p>
  <ul>
  <li>It looks like none of the graphs are being clustered the way I want them to.
  <ul>
  <li>I pass <code>weights=graph2.es[&quot;weight&quot;]</code>, the list of weights corresponding the vertices in the graph.</li>
  <li>I also explicitly pass <code>clusters=3</code> to <code>community_leading_eigenvector()</code></li>
  <li>I am still not getting any clustering based on the edge weights of this graph.</li>
  <li><strong>How to draw proper clusters, either by color, or location, or however iGraph handles differentiation of clusters?</strong></li>
  </ul>
  </li>
  <li>I am unable to find any official documentation about how to choose the number of vertices in each cluster.
  <ul>
  <li><strong>Is there a way (even roundabout) to choose the number of vertices in each cluster? It doesn't have to be <em>exact</em>, but approximate.</strong></li>
  </ul>
  </li>
  </ul>
  <p><strong>10_graph.ncol</strong></p>
  <p>Here's the .ncol file I import to form the graph.</p>
  <p>10_graph.ncol =</p>
  <pre><code>0 1 0.859412093436
  0 2 0.696674188289
  0 3 0.588339776278
  0 4 0.5104097013
  0 5 0.462457938906
  0 6 0.427462387255
  0 7 0.40350595007
  0 8 0.382509071902
  0 9 0.358689934558
  1 2 0.912797848896
  1 3 0.78532402562
  1 4 0.681472223562
  1 5 0.615574694967
  1 6 0.567507619872
  1 7 0.534715438785
  1 8 0.506595029246
  1 9 0.474297090248
  2 3 0.941218154026
  2 4 0.83850483835
  2 5 0.759542327211
  2 6 0.70025846718
  2 7 0.659110815342
  2 8 0.624313042633
  2 9 0.584580479234
  3 4 0.957468322138
  3 5 0.886571688707
  3 6 0.821838040975
  3 7 0.772665012468
  3 8 0.730820137423
  3 9 0.684372167781
  4 5 0.97372551117
  4 6 0.92168855187
  4 7 0.870589109091
  4 8 0.823583870451
  4 9 0.772154420843
  5 6 0.98093419661
  5 7 0.941236624882
  5 8 0.895874086289
  5 9 0.843755656833
  6 7 0.985707938753
  6 8 0.9523988462
  6 9 0.906031710578
  7 8 0.988193527182
  7 9 0.955898136286
  8 9 0.988293873257
  </code></pre>