# ``igraph`.`Dendrogram``

class documentation

`class Dendrogram: (source)`

Known subclasses: `igraph.VertexDendrogram`

Constructor: `Dendrogram(merges)`

View In Hierarchy

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 -+---+---

Method | `__init__` | Creates a hierarchical clustering.
Method | `__plot__` | Draws the dendrogram on the given Cairo context or matplotlib Axes.
Method | `__str__` | Undocumented
Method | `format` | Formats the dendrogram in a foreign format.
Method | `names.setter` | Sets the names of the nodes in the dendrogram
Method | `summary` | Returns the summary of the dendrogram.
Property | `merges` | Returns the performed merges in matrix format
Property | `names` | Returns the names of the nodes in the dendrogram
Static Method | `_convert_matrix_to_tuple_repr` | Converts the matrix representation of a clustering to a tuple representation.
Method | `_traverse_inorder` | Conducts an inorder traversal of the merge tree.
Instance Variable | `_merges` | Undocumented
Instance Variable | `_names` | Undocumented
Instance Variable | `_nitems` | Undocumented
Instance Variable | `_nmerges` | Undocumented

def __init__(self, merges): (source)
overridden in `igraph.VertexDendrogram`

Creates a hierarchical clustering.

Parameters
merges | the merge history either in matrix or tuple format

def __plot__(self, backend, context, *args, **kwds): (source)
overridden in `igraph.VertexDendrogram`

Draws the dendrogram on the given Cairo context or matplotlib Axes.

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`.

def __str__(self): (source)

Undocumented

def format(self, format='newick'): (source)

Formats the dendrogram in a foreign format.

Currently only the Newick format is supported.

Example:

    >>> d = Dendrogram([(2, 3), (0, 1), (4, 5)])
    >>> d.format()
    '((2,3)4,(0,1)5)6;'
    >>> d.names = list("ABCDEFG")
    >>> d.format()
    '((C,D)E,(A,B)F)G;'

@names.setter
def names(self, items): (source)

Sets the names of the nodes in the dendrogram

def summary(self, verbosity=0, max_leaf_count=40): (source)

Returns the summary of the dendrogram.

The summary includes the number of leafs and branches, and also an ASCII art representation of the dendrogram unless it is too large.

Parameters
verbosity | determines whether the ASCII representation of the dendrogram should be printed. Zero verbosity prints only the number of leafs and branches.
max_leaf_count | the maximal number of leafs to print in the ASCII representation. If the dendrogram has more leafs than this limit, the ASCII representation will not be printed even if the verbosity is larger than or equal to 1.

Returns
the summary of the dendrogram as a string.

@property
merges = (source)

Returns the performed merges in matrix format

@property
names = (source)

Returns the names of the nodes in the dendrogram

@staticmethod
def _convert_matrix_to_tuple_repr(merges, n=None): (source)

Converts the matrix representation of a clustering to a tuple representation.

Parameters
merges | the matrix representation of the clustering
n | Undocumented

Returns
the tuple representation of the clustering

def _traverse_inorder(self): (source)

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.

_merges = (source)

Undocumented

_names = (source)
overridden in `igraph.VertexDendrogram`

Undocumented

_nitems = (source)

Undocumented

_nmerges = (source)

Undocumented