title: Plot the dendrogram of communities found by NetworkX Girvan-Newman algorithm
body: <p>The Girvan-Newman algorithm for community detection in networks:</p>
  
  <blockquote>
    <p>detects communities by progressively removing edges from the original
    graph. The algorithm removes the “most valuable” edge, traditionally
    the edge with the highest betweenness centrality, at each step. As the
    graph breaks down into pieces, the tightly knit community structure is
    exposed and the result can be depicted as a dendrogram.</p>
  </blockquote>
  
  <p>In NetworkX the implementation returns an iterator over tuples of sets. First tuple is the first cut consisting of 2 communities, second tuple is the second cut consisting of 3 communities, etc., until the last tuple with n sets for n separate nodes (the leaves of the dendrogram).</p>
  
  <pre class="lang-py prettyprint-override"><code>import networkx as nx
  
  G = nx.path_graph(10)
  comp = nx.community.girvan_newman(G)
  list(comp)
  </code></pre>
  
  <blockquote>
    <p>[({0, 1, 2, 3, 4}, {5, 6, 7, 8, 9}), ({0, 1}, {2, 3, 4}, {5, 6, 7, 8,
    9}), ({0, 1}, {2, 3, 4}, {5, 6}, {8, 9, 7}), ({0, 1}, {2}, {3, 4}, {5,
    6}, {8, 9, 7}), ({0, 1}, {2}, {3, 4}, {5, 6}, {7}, {8, 9}), ({0}, {1},
    {2}, {3, 4}, {5, 6}, {7}, {8, 9}), ({0}, {1}, {2}, {3}, {4}, {5, 6},
    {7}, {8, 9}), ({0}, {1}, {2}, {3}, {4}, {5}, {6}, {7}, {8, 9}), ({0},
    {1}, {2}, {3}, {4}, {5}, {6}, {7}, {8}, {9})]</p>
  </blockquote>
  
  <p>Question is: how to plot this dendrogram?</p>
  
  <p>I've looked at <a href="https://docs.scipy.org/doc/scipy-0.14.0/reference/generated/scipy.cluster.hierarchy.dendrogram.html" rel="noreferrer"><code>scipy.cluster.hierarchy.dendrogram</code></a> but it expects a "linkage matrix" I'm guessing such as the one created by <a href="https://docs.scipy.org/doc/scipy/reference/generated/scipy.cluster.hierarchy.linkage.html" rel="noreferrer"><code>scipy.cluster.hierarchy.linkage</code></a>, but I'm not sure how I would convert this list of tuples into this "linkage matrix".</p>
  
  <p>So I'm asking how to draw this dendrogram, with/without the help of SciPy's <code>dendrogram</code>.</p>