Skip to content

Commit c7c27b6

Browse files
committed
add annotation parameter
1 parent 9ea6ee7 commit c7c27b6

File tree

1 file changed

+15
-6
lines changed

1 file changed

+15
-6
lines changed

Diff for: plotly/figure_factory/_dendrogram.py

+15-6
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@
1616

1717
def create_dendrogram(X, orientation="bottom", labels=None,
1818
colorscale=None, distfun=None,
19-
linkagefun=lambda x: sch.linkage(x, 'complete')):
19+
linkagefun=lambda x: sch.linkage(x, 'complete'),
20+
annotation=None):
2021
"""
2122
BETA function that returns a dendrogram Plotly figure object.
2223
@@ -85,7 +86,8 @@ def create_dendrogram(X, orientation="bottom", labels=None,
8586
distfun = scs.distance.pdist
8687

8788
dendrogram = _Dendrogram(X, orientation, labels, colorscale,
88-
distfun=distfun, linkagefun=linkagefun)
89+
distfun=distfun, linkagefun=linkagefun,
90+
annotation=annotation)
8991

9092
return {'layout': dendrogram.layout,
9193
'data': dendrogram.data}
@@ -97,7 +99,8 @@ class _Dendrogram(object):
9799
def __init__(self, X, orientation='bottom', labels=None, colorscale=None,
98100
width="100%", height="100%", xaxis='xaxis', yaxis='yaxis',
99101
distfun=None,
100-
linkagefun=lambda x: sch.linkage(x, 'complete')):
102+
linkagefun=lambda x: sch.linkage(x, 'complete'),
103+
annotation=None):
101104
self.orientation = orientation
102105
self.labels = labels
103106
self.xaxis = xaxis
@@ -123,7 +126,8 @@ def __init__(self, X, orientation='bottom', labels=None, colorscale=None,
123126
(dd_traces, xvals, yvals,
124127
ordered_labels, leaves) = self.get_dendrogram_traces(X, colorscale,
125128
distfun,
126-
linkagefun)
129+
linkagefun,
130+
annotation)
127131

128132
self.labels = ordered_labels
129133
self.leaves = leaves
@@ -232,7 +236,7 @@ def set_figure_layout(self, width, height):
232236

233237
return self.layout
234238

235-
def get_dendrogram_traces(self, X, colorscale, distfun, linkagefun):
239+
def get_dendrogram_traces(self, X, colorscale, distfun, linkagefun, annotation):
236240
"""
237241
Calculates all the elements needed for plotting a dendrogram.
238242
@@ -279,11 +283,16 @@ def get_dendrogram_traces(self, X, colorscale, distfun, linkagefun):
279283
else:
280284
ys = icoord[i]
281285
color_key = color_list[i]
286+
text_annotation = None
287+
if annotation:
288+
text_annotation = annotation[i]
282289
trace = graph_objs.Scatter(
283290
x=np.multiply(self.sign[self.xaxis], xs),
284291
y=np.multiply(self.sign[self.yaxis], ys),
285292
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'
287296
)
288297

289298
try:

0 commit comments

Comments
 (0)