MCPcopy Index your code
hub / github.com/plotly/plotly.py / get_dendrogram_traces

Method get_dendrogram_traces

plotly/figure_factory/_dendrogram.py:312–395  ·  view source on GitHub ↗

Calculates all the elements needed for plotting a dendrogram. :param (ndarray) X: Matrix of observations as array of arrays :param (list) colorscale: Color scale for dendrogram tree clusters :param (function) distfun: Function to compute the pairwise distance

(
        self, X, colorscale, distfun, linkagefun, hovertext, color_threshold
    )

Source from the content-addressed store, hash-verified

310 return self.layout
311
312 def get_dendrogram_traces(
313 self, X, colorscale, distfun, linkagefun, hovertext, color_threshold
314 ):
315 """
316 Calculates all the elements needed for plotting a dendrogram.
317
318 :param (ndarray) X: Matrix of observations as array of arrays
319 :param (list) colorscale: Color scale for dendrogram tree clusters
320 :param (function) distfun: Function to compute the pairwise distance
321 from the observations
322 :param (function) linkagefun: Function to compute the linkage matrix
323 from the pairwise distances
324 :param (list) hovertext: List of hovertext for constituent traces of dendrogram
325 :rtype (tuple): Contains all the traces in the following order:
326 (a) trace_list: List of Plotly trace objects for dendrogram tree
327 (b) icoord: All X points of the dendrogram tree as array of arrays
328 with length 4
329 (c) dcoord: All Y points of the dendrogram tree as array of arrays
330 with length 4
331 (d) ordered_labels: leaf labels in the order they are going to
332 appear on the plot
333 (e) P['leaves']: left-to-right traversal of the leaves
334
335 """
336 d = distfun(X)
337 Z = linkagefun(d)
338 P = sch.dendrogram(
339 Z,
340 orientation=self.orientation,
341 labels=self.labels,
342 no_plot=True,
343 color_threshold=color_threshold,
344 )
345
346 icoord = np.array(P["icoord"])
347 dcoord = np.array(P["dcoord"])
348 ordered_labels = np.array(P["ivl"])
349 color_list = np.array(P["color_list"])
350 colors = self.get_color_dict(colorscale)
351
352 trace_list = []
353
354 for i in range(len(icoord)):
355 # xs and ys are arrays of 4 points that make up the '∩' shapes
356 # of the dendrogram tree
357 if self.orientation in ["top", "bottom"]:
358 xs = icoord[i]
359 else:
360 xs = dcoord[i]
361
362 if self.orientation in ["top", "bottom"]:
363 ys = dcoord[i]
364 else:
365 ys = icoord[i]
366 color_key = color_list[i]
367 hovertext_label = None
368 if hovertext:
369 hovertext_label = hovertext[i]

Callers 1

__init__Method · 0.95

Calls 3

get_color_dictMethod · 0.95
intFunction · 0.85
arrayMethod · 0.45

Tested by

no test coverage detected