[frames] | no frames]

# Class Dendrogram

```object --+
|
Clustering --+
|
Dendrogram
```
Known Subclasses:
VertexDendrogram

The hierarchical clustering (dendrogram) of some dataset.

A hierarchical clustering means that we know not only the way the elements are separated into groups, but also the exact history of how individual elements were joined into larger subgroups.

This class internally represents the hierarchy by a matrix with n rows and 2 columns -- or more precisely, a list of lists of size 2. This is exactly the same as the original format used by `igraph`'s C core. The ith row of the matrix contains the indices of the two clusters being joined in time step i. The joint group will be represented by the ID n+i, with i starting from one. The ID of the joint group will be referenced in the upcoming steps instead of any of its individual members. So, IDs less than or equal to n (where n is the number of rows in the matrix) mean the original members of the dataset (with ID from 0 to n), while IDs up from n+1 mean joint groups. As an example, take a look at the dendrogram and the internal representation of a given clustering of five nodes:
``` 0 -+
|
1 -+-+
|
2 ---+-+        <====>   [[0, 1], [3, 4], [2, 5], [6, 7]]
|
3 -+   |
|   |
4 -+---+---
```

 Instance Methods
` ` __init__(self, merges)
Creates a hierarchical clustering.
` ` __plot__(self, context, bbox, palette, *args, **kwds)
Draws the dendrogram on the given Cairo context
` ` __str__(self)
str(x)
` ` _convert_matrix_to_tuple_repr(merges, n=None)
` ` _get_merges(self)
` ` _item_box_size(self, context, horiz, idx)
Calculates the amount of space needed for drawing an individual vertex at the bottom of the dendrogram.
` ` _plot_item(self, context, horiz, idx, x, y)
` ` _traverse_inorder(self)
Conducts an inorder traversal of the merge tree.
` ` summary(self)
Draws the dendrogram of the hierarchical clustering in a string

Inherited from `Clustering`: `__getitem__`, `__len__`, `size`, `size_histogram`, `sizes`

Inherited from `Clustering` (private): `_get_membership`

Inherited from `object`: `__delattr__`, `__getattribute__`, `__hash__`, `__new__`, `__reduce__`, `__reduce_ex__`, `__repr__`, `__setattr__`

 Properties
` ` merges
The performed merges in matrix format

Inherited from `Clustering`: `membership`

Inherited from `object`: `__class__`

 Method Details

### __init__(self, merges)(Constructor)

Creates a hierarchical clustering.
Parameters:
• `merges` - the merge history either in matrix or tuple format
Overrides: Clustering.__init__

### __plot__(self, context, bbox, palette, *args, **kwds)

Draws the dendrogram on the given Cairo context

Supported keyword arguments are:
• `orientation`: the orientation of the dendrogram. Must be one of the following values: `left-right`, `bottom-top`, `right-left` or `top-bottom`. Individual elements are always placed at the former edge and merges are performed towards the latter edge. Possible aliases: `horizontal` = `left-right`, `vertical` = `bottom-top`, `lr` = `left-right`, `rl` = `right-left`, `tb` = `top-bottom`, `bt` = `bottom-top`. The default is `left-right`.

### __str__(self)(Informal representation operator)

str(x)
Overrides: object.__str__
(inherited documentation)

None

None

### _item_box_size(self, context, horiz, idx)

Calculates the amount of space needed for drawing an individual vertex at the bottom of the dendrogram.

None

### _traverse_inorder(self)

Conducts an inorder traversal of the merge tree.

The inorder traversal returns the nodes on the last level in the order they should be drawn so that no edges cross each other.
Returns:
the result of the inorder traversal in a list.

### summary(self)

Draws the dendrogram of the hierarchical clustering in a string

 Property Details

### merges

The performed merges in matrix format
Get Method:
Set Method:
 ```None                                                                   ```
Delete Method:
 ```None                                                                   ```

 Generated by Epydoc 3.0alpha3 on Thu Feb 14 12:44:01 2008 http://epydoc.sourceforge.net