17
17
def create_dendrogram (X , orientation = "bottom" , labels = None ,
18
18
colorscale = None , distfun = None ,
19
19
linkagefun = lambda x : sch .linkage (x , 'complete' ),
20
- hovertext = None ):
20
+ hovertext = None , color_threshold = None ):
21
21
"""
22
22
BETA function that returns a dendrogram Plotly figure object.
23
23
@@ -28,10 +28,10 @@ def create_dendrogram(X, orientation="bottom", labels=None,
28
28
:param (function) distfun: Function to compute the pairwise distance from
29
29
the observations
30
30
:param (function) linkagefun: Function to compute the linkage matrix from
31
- the pairwise distances
31
+ the pairwise distances
32
32
:param (list[list]) hovertext: List of hovertext for constituent traces of dendrogram
33
-
34
- clusters
33
+ clusters
34
+ :param (double) color_threshold: Value at which the separation of clusters will be made
35
35
36
36
Example 1: Simple bottom oriented dendrogram
37
37
```
@@ -88,7 +88,7 @@ def create_dendrogram(X, orientation="bottom", labels=None,
88
88
89
89
dendrogram = _Dendrogram (X , orientation , labels , colorscale ,
90
90
distfun = distfun , linkagefun = linkagefun ,
91
- hovertext = hovertext )
91
+ hovertext = hovertext , color_threshold = color_threshold )
92
92
93
93
return graph_objs .Figure (data = dendrogram .data ,
94
94
layout = dendrogram .layout )
@@ -101,7 +101,7 @@ def __init__(self, X, orientation='bottom', labels=None, colorscale=None,
101
101
width = np .inf , height = np .inf , xaxis = 'xaxis' , yaxis = 'yaxis' ,
102
102
distfun = None ,
103
103
linkagefun = lambda x : sch .linkage (x , 'complete' ),
104
- hovertext = None ):
104
+ hovertext = None , color_threshold = None ):
105
105
self .orientation = orientation
106
106
self .labels = labels
107
107
self .xaxis = xaxis
@@ -128,7 +128,8 @@ def __init__(self, X, orientation='bottom', labels=None, colorscale=None,
128
128
ordered_labels , leaves ) = self .get_dendrogram_traces (X , colorscale ,
129
129
distfun ,
130
130
linkagefun ,
131
- hovertext )
131
+ hovertext ,
132
+ color_threshold )
132
133
133
134
self .labels = ordered_labels
134
135
self .leaves = leaves
@@ -249,7 +250,7 @@ def set_figure_layout(self, width, height):
249
250
250
251
return self .layout
251
252
252
- def get_dendrogram_traces (self , X , colorscale , distfun , linkagefun , hovertext ):
253
+ def get_dendrogram_traces (self , X , colorscale , distfun , linkagefun , hovertext , color_threshold ):
253
254
"""
254
255
Calculates all the elements needed for plotting a dendrogram.
255
256
@@ -274,7 +275,8 @@ def get_dendrogram_traces(self, X, colorscale, distfun, linkagefun, hovertext):
274
275
d = distfun (X )
275
276
Z = linkagefun (d )
276
277
P = sch .dendrogram (Z , orientation = self .orientation ,
277
- labels = self .labels , no_plot = True )
278
+ labels = self .labels , no_plot = True ,
279
+ color_threshold = color_threshold )
278
280
279
281
icoord = scp .array (P ['icoord' ])
280
282
dcoord = scp .array (P ['dcoord' ])
0 commit comments