Repository: scipy/scipy

Issue:
Dendrogram: enable leaves labelling with 'labels' when using 'truncate_mode'
**Is your feature request related to a problem? Please describe.**
Hi!

My feature request is about `cluster.hierarchy.dendrogram` function.
I've noticed, that when using `truncate_mode` it's impossible to label leaf nodes using `labels` parameter. The only solution is using `leaf_label_func`. I personally don't have many professional experience in using `hierarchy.dendrogram`, but for sure there are people who can express whether proposed feature would be useful.

**Describe the solution you'd like**
I suggest to make it possible to use `labels` together with `truncate_mode` function. E.g. to enable labelling leaves after truncation with list.

@ihowell @rgommers as far as I know You might be the right people to ask about the opinion. Would be grateful for some thoughts about that. 

I personally think that it's possible to implement, thought it might be a bit tricky.


That's the situtation I'm talking about:
```
from matplotlib import pyplot as plt
import matplotlib

from scipy.cluster import hierarchy

X = [[0,0], [0,1], [0,4], [2,4], [6,3],[7,3], [8,3]]
Z = hierarchy.linkage(X, method='single')

fig, axes = plt.subplots(1, 2, figsize=(15, 6))
dn_1 = hierarchy.dendrogram(Z, ax = axes[0])
dn_2 = hierarchy.dendrogram(Z, ax = axes[1], truncate_mode='lastp', p=3)

plt.show()
```
![plot2](https://user-images.githubusercontent.com/36896640/82944770-15f03600-9f9c-11ea-9b68-a11497c66ca5.png)





Discussion:
I'm not sure this combination of truncation and `labels` makes sense, given that `labels` is explicitly documented as being for original observations.

I'd be inclined to just add an understandable example with `leaf_label_func` here.
@rgommers  something like "With `leaf_label_func` you can also label your leaves after truncation, and here's how: ..." ?
Yes indeed. The `leaf_label_func` parameter description already contains a small example, but the longer one using `truncate_mode` and `leaf_label_func` together could go in the Examples section. And then refer to it from the `labels` parameter description if that makes sense to you.

Resolving patch:
diff --git a/scipy/cluster/hierarchy.py b/scipy/cluster/hierarchy.py
--- a/scipy/cluster/hierarchy.py
+++ b/scipy/cluster/hierarchy.py
@@ -3158,7 +3158,7 @@ def dendrogram(Z, p=30, truncate_mode=None, color_threshold=None,
         unspecified, the size based on the number of nodes in the
         dendrogram.
     leaf_label_func : lambda or function, optional
-        When leaf_label_func is a callable function, for each
+        When ``leaf_label_func`` is a callable function, for each
         leaf with cluster index :math:`k < 2n-1`. The function
         is expected to return a string with the label for the
         leaf.
@@ -3177,10 +3177,16 @@ def llf(id):
                     return str(id)
                 else:
                     return '[%d %d %1.2f]' % (id, count, R[n-id,3])
+
             # The text for the leaf nodes is going to be big so force
             # a rotation of 90 degrees.
             dendrogram(Z, leaf_label_func=llf, leaf_rotation=90)
 
+            # leaf_label_func can also be used together with ``truncate_mode`` parameter,
+            # in which case you will get your leaves labeled after truncation:
+            dendrogram(Z, leaf_label_func=llf, leaf_rotation=90,
+                       truncate_mode='level', p=2)
+
     show_contracted : bool, optional
         When True the heights of non-singleton nodes contracted
         into a leaf node are plotted as crosses along the link


Test patch: