@@ -21,59 +21,63 @@ def create_dendrogram(
21
21
color_threshold = None ,
22
22
):
23
23
"""
24
- Function that returns a dendrogram Plotly figure object. This is a thin
25
- wrapper around scipy.cluster.hierarchy.dendrogram.
26
-
27
- See also https://dash.plot.ly/dash-bio/clustergram.
28
-
29
- :param (ndarray) X: Matrix of observations as array of arrays
30
- :param (str) orientation: 'top', 'right', 'bottom', or 'left'
31
- :param (list) labels: List of axis category labels(observation labels)
32
- :param (list) colorscale: Optional colorscale for the dendrogram tree.
33
- Requires 8 colors to be specified, the 7th of
34
- which is ignored. With scipy>=1.5.0, the 2nd, 3rd
35
- and 6th are used twice as often as the others.
36
- Given a shorter list, the missing values are
37
- replaced with defaults and with a longer list the
38
- extra values are ignored.
39
- :param (function) distfun: Function to compute the pairwise distance from
40
- the observations
41
- :param (function) linkagefun: Function to compute the linkage matrix from
42
- the pairwise distances
43
- :param (list[list]) hovertext: List of hovertext for constituent traces of dendrogram
44
- clusters
45
- :param (double) color_threshold: Value at which the separation of clusters will be made
46
-
24
+ Create a dendrogram Plotly figure object.
25
+
26
+ This function is a thin wrapper around `scipy.cluster.hierarchy.dendrogram`.
27
+
28
+ Parameters
29
+ ----------
30
+ X : ndarray
31
+ Matrix of observations as array of arrays.
32
+ orientation : str
33
+ 'top', 'right', 'bottom', or 'left'. Default is 'bottom'.
34
+ labels : list
35
+ List of axis category labels (observation labels).
36
+ colorscale : list
37
+ Optional colorscale for the dendrogram tree. Requires 8 colors to be specified,
38
+ the 7th of which is ignored. With scipy>=1.5.0, the 2nd, 3rd, and 6th are used
39
+ twice as often as the others. Given a shorter list, the missing values are replaced
40
+ with defaults and with a longer list the extra values are ignored.
41
+ distfun : function
42
+ Function to compute the pairwise distance from the observations.
43
+ linkagefun : function
44
+ Function to compute the linkage matrix from the pairwise distances.
45
+ hovertext : list of list
46
+ List of hovertext for constituent traces of dendrogram clusters.
47
+ color_threshold : float
48
+ Value at which the separation of clusters will be made.
49
+
50
+ Returns
51
+ -------
52
+ plotly.graph_objs._figure.Figure
53
+ A Plotly figure object representing the dendrogram.
54
+
55
+ Examples
56
+ --------
47
57
Example 1: Simple bottom oriented dendrogram
48
58
49
59
>>> from plotly.figure_factory import create_dendrogram
50
-
51
60
>>> import numpy as np
52
-
53
- >>> X = np.random.rand(10,10)
61
+ >>> X = np.random.rand(10, 10)
54
62
>>> fig = create_dendrogram(X)
55
63
>>> fig.show()
56
64
57
65
Example 2: Dendrogram to put on the left of the heatmap
58
66
59
67
>>> from plotly.figure_factory import create_dendrogram
60
-
61
68
>>> import numpy as np
62
-
63
- >>> X = np.random.rand(5,5)
69
+ >>> X = np.random.rand(5, 5)
64
70
>>> names = ['Jack', 'Oxana', 'John', 'Chelsea', 'Mark']
65
71
>>> dendro = create_dendrogram(X, orientation='right', labels=names)
66
- >>> dendro.update_layout({'width':700, 'height':500}) # doctest: +SKIP
72
+ >>> dendro.update_layout({'width': 700, 'height': 500}) # doctest: +SKIP
67
73
>>> dendro.show()
68
74
69
75
Example 3: Dendrogram with Pandas
70
76
71
77
>>> from plotly.figure_factory import create_dendrogram
72
-
73
78
>>> import numpy as np
74
79
>>> import pandas as pd
75
-
76
- >>> Index= ['A','B','C','D','E','F','G','H','I','J']
80
+ >>> Index = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J']
77
81
>>> df = pd.DataFrame(abs(np.random.randn(10, 10)), index=Index)
78
82
>>> fig = create_dendrogram(df, labels=Index)
79
83
>>> fig.show()
0 commit comments