(
self,
X,
orientation="bottom",
labels=None,
colorscale=None,
width=np.inf,
height=np.inf,
xaxis="xaxis",
yaxis="yaxis",
distfun=None,
linkagefun=lambda x: sch.linkage(x, "complete"),
hovertext=None,
color_threshold=None,
)
| 109 | """Refer to FigureFactory.create_dendrogram() for docstring.""" |
| 110 | |
| 111 | def __init__( |
| 112 | self, |
| 113 | X, |
| 114 | orientation="bottom", |
| 115 | labels=None, |
| 116 | colorscale=None, |
| 117 | width=np.inf, |
| 118 | height=np.inf, |
| 119 | xaxis="xaxis", |
| 120 | yaxis="yaxis", |
| 121 | distfun=None, |
| 122 | linkagefun=lambda x: sch.linkage(x, "complete"), |
| 123 | hovertext=None, |
| 124 | color_threshold=None, |
| 125 | ): |
| 126 | self.orientation = orientation |
| 127 | self.labels = labels |
| 128 | self.xaxis = xaxis |
| 129 | self.yaxis = yaxis |
| 130 | self.data = [] |
| 131 | self.leaves = [] |
| 132 | self.sign = {self.xaxis: 1, self.yaxis: 1} |
| 133 | self.layout = {self.xaxis: {}, self.yaxis: {}} |
| 134 | |
| 135 | if self.orientation in ["left", "bottom"]: |
| 136 | self.sign[self.xaxis] = 1 |
| 137 | else: |
| 138 | self.sign[self.xaxis] = -1 |
| 139 | |
| 140 | if self.orientation in ["right", "bottom"]: |
| 141 | self.sign[self.yaxis] = 1 |
| 142 | else: |
| 143 | self.sign[self.yaxis] = -1 |
| 144 | |
| 145 | if distfun is None: |
| 146 | distfun = scs.distance.pdist |
| 147 | |
| 148 | (dd_traces, xvals, yvals, ordered_labels, leaves) = self.get_dendrogram_traces( |
| 149 | X, colorscale, distfun, linkagefun, hovertext, color_threshold |
| 150 | ) |
| 151 | |
| 152 | self.labels = ordered_labels |
| 153 | self.leaves = leaves |
| 154 | yvals_flat = yvals.flatten() |
| 155 | xvals_flat = xvals.flatten() |
| 156 | |
| 157 | self.zero_vals = [] |
| 158 | |
| 159 | for i in range(len(yvals_flat)): |
| 160 | if yvals_flat[i] == 0.0 and xvals_flat[i] not in self.zero_vals: |
| 161 | self.zero_vals.append(xvals_flat[i]) |
| 162 | |
| 163 | if len(self.zero_vals) > len(yvals) + 1: |
| 164 | # If the length of zero_vals is larger than the length of yvals, |
| 165 | # it means that there are wrong vals because of the identicial samples. |
| 166 | # Three and more identicial samples will make the yvals of spliting |
| 167 | # center into 0 and it will accidentally take it as leaves. |
| 168 | l_border = int(min(self.zero_vals)) |
nothing calls this directly
no test coverage detected