title: Display cluster labels for a scipy dendrogram
body: <p>I'm using hierarchical clustering to cluster word vectors, and I want the user to be able to display a dendrogram showing the clusters. However, since there can be thousands of words, I want this dendrogram to be truncated to some reasonable valuable, with the label for each leaf being a string of the most significant words in that cluster.</p>
  
  <p>My problem is that, <a href="http://students.mimuw.edu.pl/~pbechler/scipy_doc/generated/scipy.cluster.hierarchy.dendrogram.html" rel="noreferrer">according to the docs</a>, <em>"The labels[i] value is the text to put under the ith leaf node only if it corresponds to an original observation and not a non-singleton cluster."</em> I take this to mean I can't label clusters, only singular points?</p>
  
  <p>To illustrate, here is a short python script which generates a simple labeled dendrogram:</p>
  
  <pre><code>import numpy as np
  from scipy.cluster.hierarchy import dendrogram, linkage
  from matplotlib import pyplot as plt
  
  randomMatrix = np.random.uniform(-10,10,size=(20,3))
  linked = linkage(randomMatrix, 'ward')
  
  labelList = ["foo" for i in range(0, 20)]
  
  plt.figure(figsize=(15, 12))
  dendrogram(
              linked,
              orientation='right',
              labels=labelList,
              distance_sort='descending',
              show_leaf_counts=False
            )
  plt.show()
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/57Ujl.png" rel="noreferrer"><img src="https://i.stack.imgur.com/57Ujl.png" alt="a dendrogram of randomly generated points"></a></p>
  
  <p>Now let's say I want to truncate to just 5 leaves, and for each leaf, label it like "foo, foo, foo...", ie the words that make up that cluster. (Note: generating these labels is not the issue here.) I truncate it, and supply a label list to match:</p>
  
  <pre><code>labelList = ["foo, foo, foo..." for i in range(0, 5)]
  dendrogram(
              linked,
              orientation='right',
              p=5,
              truncate_mode='lastp',
              labels=labelList,
              distance_sort='descending',
              show_leaf_counts=False
            )
  </code></pre>
  
  <p>and here's the problem, no labels:</p>
  
  <p><a href="https://i.stack.imgur.com/br0O4.png" rel="noreferrer"><img src="https://i.stack.imgur.com/br0O4.png" alt="enter image description here"></a></p>
  
  <p>I'm thinking there might be a use here for the parameter 'leaf_label_func' but I'm not sure how to use it.</p>