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
@@ -32,6 +32,7 @@ def create_dendrogram(X, orientation="bottom", labels=None,
32
32
:param (list[list]) hovertext: List of hovertext for constituent traces of dendrogram
33
33
34
34
clusters
35
+ :param (function) color_threshold: function to colour clusters under a set threshold
35
36
36
37
Example 1: Simple bottom oriented dendrogram
37
38
```
@@ -88,7 +89,7 @@ def create_dendrogram(X, orientation="bottom", labels=None,
88
89
89
90
dendrogram = _Dendrogram (X , orientation , labels , colorscale ,
90
91
distfun = distfun , linkagefun = linkagefun ,
91
- hovertext = hovertext )
92
+ hovertext = hovertext , color_threshold = color_threshold )
92
93
93
94
return graph_objs .Figure (data = dendrogram .data , layout = dendrogram .layout )
94
95
@@ -100,7 +101,7 @@ def __init__(self, X, orientation='bottom', labels=None, colorscale=None,
100
101
width = "100%" , height = "100%" , xaxis = 'xaxis' , yaxis = 'yaxis' ,
101
102
distfun = None ,
102
103
linkagefun = lambda x : sch .linkage (x , 'complete' ),
103
- hovertext = None ):
104
+ hovertext = None , color_threshold = None ):
104
105
self .orientation = orientation
105
106
self .labels = labels
106
107
self .xaxis = xaxis
@@ -127,7 +128,8 @@ def __init__(self, X, orientation='bottom', labels=None, colorscale=None,
127
128
ordered_labels , leaves ) = self .get_dendrogram_traces (X , colorscale ,
128
129
distfun ,
129
130
linkagefun ,
130
- hovertext )
131
+ hovertext ,
132
+ color_threshold )
131
133
132
134
self .labels = ordered_labels
133
135
self .leaves = leaves
@@ -236,7 +238,7 @@ def set_figure_layout(self, width, height):
236
238
237
239
return self .layout
238
240
239
- def get_dendrogram_traces (self , X , colorscale , distfun , linkagefun , hovertext ):
241
+ def get_dendrogram_traces (self , X , colorscale , distfun , linkagefun , hovertext , color_threshold ):
240
242
"""
241
243
Calculates all the elements needed for plotting a dendrogram.
242
244
@@ -247,6 +249,7 @@ def get_dendrogram_traces(self, X, colorscale, distfun, linkagefun, hovertext):
247
249
:param (function) linkagefun: Function to compute the linkage matrix
248
250
from the pairwise distances
249
251
:param (list) hovertext: List of hovertext for constituent traces of dendrogram
252
+ :param (list) color_threshold: sets the color of cluster under set threshold
250
253
:rtype (tuple): Contains all the traces in the following order:
251
254
(a) trace_list: List of Plotly trace objects for dendrogram tree
252
255
(b) icoord: All X points of the dendrogram tree as array of arrays
@@ -261,7 +264,7 @@ def get_dendrogram_traces(self, X, colorscale, distfun, linkagefun, hovertext):
261
264
d = distfun (X )
262
265
Z = linkagefun (d )
263
266
P = sch .dendrogram (Z , orientation = self .orientation ,
264
- labels = self .labels , no_plot = True )
267
+ labels = self .labels , no_plot = True , color_threshold = color_threshold )
265
268
266
269
icoord = scp .array (P ['icoord' ])
267
270
dcoord = scp .array (P ['dcoord' ])
0 commit comments