Skip to content

Data Containers

idendrogram.Dendrogram dataclass

Dataclass representing the idendrogram dendrogram object.

Source code in idendrogram/containers.py
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
@dataclass
class Dendrogram:
    """Dataclass representing the idendrogram dendrogram object.
    """

    axis_labels: List[AxisLabel]
    """axis_labels: list of AxisLabel objects"""
    links: List[ClusterLink]
    """links: list of ClusterLink objects"""
    nodes: List[ClusterNode]
    """nodes: list of ClusterNode objects"""
    computed_nodes: bool = True
    """computed_nodes: boolean indicating if Cluster Nodes were computed at creation time"""
    x_domain: Tuple[float, float] = (0, 0)
    """x_domain: the value domain of the label axis"""
    y_domain: Tuple[float, float] = (0, 0)
    """y_domain: the value domain of the value axis"""

    def plot(
        self,
        backend: str = "altair",
        orientation: str = "top",
        show_nodes: bool = True,
        height: float = 400,
        width: float = 400,
        scale: str = "linear",
    ) -> Any:
        """
        Plot the dendrogram using one of the supported backends. This is a convenience function,
            you can also use `to_*()` functions from appropriate target backends at `idendrogram.targets.[backend].to_[backend]()`.

        Args:
            backend (str, optional): Backend to use, one of 'altair', 'streamlit', 'plotly', 'matplotlib'. 
            orientation (str, optional): Position of dendrogram's root node. One of "top", "bottom", "left", "right". 
            show_nodes (bool, optional): Whether to draw nodes. 
            height (float, optional): Height of the dendrogram. 
            width (float, optional): Width of the dendrogram. 
            scale (str, optional): Scale used for the value axis. One of "linear", "symlog", "log". 

        Raises:
            ValueError: Parameters supplied did not comform to allowed values.  

        Returns:
            Any: 

                Varies by backend: 

                - Altair: `altair.Layered` chart object
                - Plotly: `plotly.graph_objs.Figure` figure object
                - Matplotlib: `matplotlib.pyplot.ax` axes object
                - Streamlit: [idendrogram.ClusterNode][] object that was clicked on (None if no clicks took place)
        """
        if backend == 'altair':
            from .targets.altair import to_altair
            return to_altair(self, orientation=orientation, show_nodes=show_nodes, height=height, width=width, scale=scale)
        elif backend == 'matplotlib':
            from .targets.matplotlib import to_matplotlib
            return to_matplotlib(self, orientation=orientation, show_nodes=show_nodes, height=height, width=width, scale=scale)
        elif backend == 'plotly':
            from .targets.plotly import to_plotly
            return to_plotly(self, orientation=orientation, show_nodes=show_nodes, height=height, width=width, scale=scale)
        elif backend == 'streamlit':
            from .targets.streamlit import to_streamlit
            return to_streamlit(self, orientation=orientation, show_nodes=show_nodes, height=height, width=width, scale=scale)
        else:
            raise ValueError(f"Unsupported backend '{backend}', should be one of 'plotly', 'matplotlib', 'altair', 'streamlit'")

    def to_json(self) -> str:
        """Converts dendrogram to JSON representation.

        Returns:
            str: JSON-formatted dendrogram
        """
        from .targets.json import to_json
        return to_json(self)

axis_labels: List[AxisLabel] instance-attribute

axis_labels: list of AxisLabel objects

computed_nodes: bool = True class-attribute instance-attribute

computed_nodes: boolean indicating if Cluster Nodes were computed at creation time

links: list of ClusterLink objects

nodes: List[ClusterNode] instance-attribute

nodes: list of ClusterNode objects

x_domain: Tuple[float, float] = (0, 0) class-attribute instance-attribute

x_domain: the value domain of the label axis

y_domain: Tuple[float, float] = (0, 0) class-attribute instance-attribute

y_domain: the value domain of the value axis

plot(backend='altair', orientation='top', show_nodes=True, height=400, width=400, scale='linear')

Plot the dendrogram using one of the supported backends. This is a convenience function, you can also use to_*() functions from appropriate target backends at idendrogram.targets.[backend].to_[backend]().

Parameters:

Name Type Description Default
backend str

Backend to use, one of 'altair', 'streamlit', 'plotly', 'matplotlib'.

'altair'
orientation str

Position of dendrogram's root node. One of "top", "bottom", "left", "right".

'top'
show_nodes bool

Whether to draw nodes.

True
height float

Height of the dendrogram.

400
width float

Width of the dendrogram.

400
scale str

Scale used for the value axis. One of "linear", "symlog", "log".

'linear'

Raises:

Type Description
ValueError

Parameters supplied did not comform to allowed values.

Returns:

Name Type Description
Any Any

Varies by backend:

  • Altair: altair.Layered chart object
  • Plotly: plotly.graph_objs.Figure figure object
  • Matplotlib: matplotlib.pyplot.ax axes object
  • Streamlit: idendrogram.ClusterNode object that was clicked on (None if no clicks took place)
Source code in idendrogram/containers.py
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
def plot(
    self,
    backend: str = "altair",
    orientation: str = "top",
    show_nodes: bool = True,
    height: float = 400,
    width: float = 400,
    scale: str = "linear",
) -> Any:
    """
    Plot the dendrogram using one of the supported backends. This is a convenience function,
        you can also use `to_*()` functions from appropriate target backends at `idendrogram.targets.[backend].to_[backend]()`.

    Args:
        backend (str, optional): Backend to use, one of 'altair', 'streamlit', 'plotly', 'matplotlib'. 
        orientation (str, optional): Position of dendrogram's root node. One of "top", "bottom", "left", "right". 
        show_nodes (bool, optional): Whether to draw nodes. 
        height (float, optional): Height of the dendrogram. 
        width (float, optional): Width of the dendrogram. 
        scale (str, optional): Scale used for the value axis. One of "linear", "symlog", "log". 

    Raises:
        ValueError: Parameters supplied did not comform to allowed values.  

    Returns:
        Any: 

            Varies by backend: 

            - Altair: `altair.Layered` chart object
            - Plotly: `plotly.graph_objs.Figure` figure object
            - Matplotlib: `matplotlib.pyplot.ax` axes object
            - Streamlit: [idendrogram.ClusterNode][] object that was clicked on (None if no clicks took place)
    """
    if backend == 'altair':
        from .targets.altair import to_altair
        return to_altair(self, orientation=orientation, show_nodes=show_nodes, height=height, width=width, scale=scale)
    elif backend == 'matplotlib':
        from .targets.matplotlib import to_matplotlib
        return to_matplotlib(self, orientation=orientation, show_nodes=show_nodes, height=height, width=width, scale=scale)
    elif backend == 'plotly':
        from .targets.plotly import to_plotly
        return to_plotly(self, orientation=orientation, show_nodes=show_nodes, height=height, width=width, scale=scale)
    elif backend == 'streamlit':
        from .targets.streamlit import to_streamlit
        return to_streamlit(self, orientation=orientation, show_nodes=show_nodes, height=height, width=width, scale=scale)
    else:
        raise ValueError(f"Unsupported backend '{backend}', should be one of 'plotly', 'matplotlib', 'altair', 'streamlit'")

to_json()

Converts dendrogram to JSON representation.

Returns:

Name Type Description
str str

JSON-formatted dendrogram

Source code in idendrogram/containers.py
162
163
164
165
166
167
168
169
def to_json(self) -> str:
    """Converts dendrogram to JSON representation.

    Returns:
        str: JSON-formatted dendrogram
    """
    from .targets.json import to_json
    return to_json(self)

idendrogram.AxisLabel dataclass

Dataclass storing information on axis labels.

Source code in idendrogram/containers.py
84
85
86
87
88
89
90
91
92
93
@dataclass
class AxisLabel:
    """Dataclass storing information on axis labels."""

    x: float
    """x-coordinate of the label"""
    label: str
    """label text"""
    labelAngle: float = 0
    """rotation of the text label (in degrees)"""

label: str instance-attribute

label text

labelAngle: float = 0 class-attribute instance-attribute

rotation of the text label (in degrees)

x: float instance-attribute

x-coordinate of the label

Dataclass storing information about links.

Source code in idendrogram/containers.py
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
@dataclass
class ClusterLink:
    """Dataclass storing information about links."""

    x: List[float]
    """x: 4 coordinates of the link on the x-axis"""
    y: List[float]
    """y: 4 coordinates of the link on the y-axis"""
    fillcolor: str
    """fillcolor: line color used for the link"""
    id: Union[int, None] = None
    """id: the linkage ID represented by the link"""
    children_id: Union[Tuple[int, int], None] = None
    """children_id: a tuple of 2 linkage IDs representing the 2 immediate clusters that got merged into this cluster"""
    cluster_id: Union[int, None] = None
    """cluster_id: flat cluster assignment ID if this link represents a flat cluster; otherwise empty"""
    strokewidth: float = 1.0
    """strokewidth: the line width of the link"""
    strokedash: List = field(default_factory=lambda: [1, 0])
    """strokedash: the dash pattern used for the link"""
    strokeopacity: float = 1.0
    """strokeopacity: the opacity level used for the link"""
    _order_helper: List = field(default_factory=lambda: [0, 1, 2, 3])

children_id: Union[Tuple[int, int], None] = None class-attribute instance-attribute

children_id: a tuple of 2 linkage IDs representing the 2 immediate clusters that got merged into this cluster

cluster_id: Union[int, None] = None class-attribute instance-attribute

cluster_id: flat cluster assignment ID if this link represents a flat cluster; otherwise empty

fillcolor: str instance-attribute

fillcolor: line color used for the link

id: Union[int, None] = None class-attribute instance-attribute

id: the linkage ID represented by the link

strokedash: List = field(default_factory=lambda : [1, 0]) class-attribute instance-attribute

strokedash: the dash pattern used for the link

strokeopacity: float = 1.0 class-attribute instance-attribute

strokeopacity: the opacity level used for the link

strokewidth: float = 1.0 class-attribute instance-attribute

strokewidth: the line width of the link

x: List[float] instance-attribute

x: 4 coordinates of the link on the x-axis

y: List[float] instance-attribute

y: 4 coordinates of the link on the y-axis

idendrogram.ClusterNode dataclass

Data class storing node-level information.

Source code in idendrogram/containers.py
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
@dataclass
class ClusterNode:
    """Data class storing node-level information."""

    x: float
    """X-coordinate of the node"""
    y: float
    """Y-coordinate of the node"""
    type: str
    """Type of the node. One of `leaf`, `subcluster`, `cluster`, `supercluster` """
    id: int
    """Linkage ID the node represents"""
    cluster_id: Union[int, None]
    """flat cluster assignment ID if this link represents a flat cluster; otherwise empty"""
    edgecolor: str
    """color used for the edge of the node"""
    label: str = ""
    """text label displayed on the node"""
    hovertext: Dict[str, str] = field(default_factory=dict)
    """Information displayed on a tooltip, in dictionary form (key: values)"""
    fillcolor: str = "#fff"
    """colors used to fill the node"""
    radius: float = 7.0
    """radius of the node"""
    opacity: float = 1.0
    """opacity level of the node"""
    labelsize: float = 10.0
    """size of the text label displayed"""
    labelcolor: str = "#fff"
    """color of the text label displayed"""
    _default_leaf_radius: float = 4.0
    """size of the radius of the leaf nodes"""
    _default_leaf_radius_if_cluster: float = 7.0
    """size of the radius of the leaf nodes"""

cluster_id: Union[int, None] instance-attribute

flat cluster assignment ID if this link represents a flat cluster; otherwise empty

edgecolor: str instance-attribute

color used for the edge of the node

fillcolor: str = '#fff' class-attribute instance-attribute

colors used to fill the node

hovertext: Dict[str, str] = field(default_factory=dict) class-attribute instance-attribute

Information displayed on a tooltip, in dictionary form (key: values)

id: int instance-attribute

Linkage ID the node represents

label: str = '' class-attribute instance-attribute

text label displayed on the node

labelcolor: str = '#fff' class-attribute instance-attribute

color of the text label displayed

labelsize: float = 10.0 class-attribute instance-attribute

size of the text label displayed

opacity: float = 1.0 class-attribute instance-attribute

opacity level of the node

radius: float = 7.0 class-attribute instance-attribute

radius of the node

type: str instance-attribute

Type of the node. One of leaf, subcluster, cluster, supercluster

x: float instance-attribute

X-coordinate of the node

y: float instance-attribute

Y-coordinate of the node