16
16
17
17
def create_dendrogram (X , orientation = "bottom" , labels = None ,
18
18
colorscale = None , distfun = None ,
19
- linkagefun = lambda x : sch .linkage (x , 'complete' )):
19
+ linkagefun = lambda x : sch .linkage (x , 'complete' ),
20
+ annotation = None ):
20
21
"""
21
22
BETA function that returns a dendrogram Plotly figure object.
22
23
@@ -85,7 +86,8 @@ def create_dendrogram(X, orientation="bottom", labels=None,
85
86
distfun = scs .distance .pdist
86
87
87
88
dendrogram = _Dendrogram (X , orientation , labels , colorscale ,
88
- distfun = distfun , linkagefun = linkagefun )
89
+ distfun = distfun , linkagefun = linkagefun ,
90
+ annotation = annotation )
89
91
90
92
return {'layout' : dendrogram .layout ,
91
93
'data' : dendrogram .data }
@@ -97,7 +99,8 @@ class _Dendrogram(object):
97
99
def __init__ (self , X , orientation = 'bottom' , labels = None , colorscale = None ,
98
100
width = "100%" , height = "100%" , xaxis = 'xaxis' , yaxis = 'yaxis' ,
99
101
distfun = None ,
100
- linkagefun = lambda x : sch .linkage (x , 'complete' )):
102
+ linkagefun = lambda x : sch .linkage (x , 'complete' ),
103
+ annotation = None ):
101
104
self .orientation = orientation
102
105
self .labels = labels
103
106
self .xaxis = xaxis
@@ -123,7 +126,8 @@ def __init__(self, X, orientation='bottom', labels=None, colorscale=None,
123
126
(dd_traces , xvals , yvals ,
124
127
ordered_labels , leaves ) = self .get_dendrogram_traces (X , colorscale ,
125
128
distfun ,
126
- linkagefun )
129
+ linkagefun ,
130
+ annotation )
127
131
128
132
self .labels = ordered_labels
129
133
self .leaves = leaves
@@ -232,7 +236,7 @@ def set_figure_layout(self, width, height):
232
236
233
237
return self .layout
234
238
235
- def get_dendrogram_traces (self , X , colorscale , distfun , linkagefun ):
239
+ def get_dendrogram_traces (self , X , colorscale , distfun , linkagefun , annotation ):
236
240
"""
237
241
Calculates all the elements needed for plotting a dendrogram.
238
242
@@ -279,11 +283,16 @@ def get_dendrogram_traces(self, X, colorscale, distfun, linkagefun):
279
283
else :
280
284
ys = icoord [i ]
281
285
color_key = color_list [i ]
286
+ text_annotation = None
287
+ if annotation :
288
+ text_annotation = annotation [i ]
282
289
trace = graph_objs .Scatter (
283
290
x = np .multiply (self .sign [self .xaxis ], xs ),
284
291
y = np .multiply (self .sign [self .yaxis ], ys ),
285
292
mode = 'lines' ,
286
- marker = graph_objs .Marker (color = colors [color_key ])
293
+ marker = graph_objs .Marker (color = colors [color_key ]),
294
+ text = text_annotation ,
295
+ hoverinfo = 'text'
287
296
)
288
297
289
298
try :
0 commit comments