Refer to TraceFactory.create_annotated_heatmap() for docstring
| 166 | |
| 167 | |
| 168 | class _AnnotatedHeatmap(object): |
| 169 | """ |
| 170 | Refer to TraceFactory.create_annotated_heatmap() for docstring |
| 171 | """ |
| 172 | |
| 173 | def __init__( |
| 174 | self, z, x, y, annotation_text, colorscale, font_colors, reversescale, **kwargs |
| 175 | ): |
| 176 | self.z = z |
| 177 | if x: |
| 178 | self.x = x |
| 179 | else: |
| 180 | self.x = range(len(z[0])) |
| 181 | if y: |
| 182 | self.y = y |
| 183 | else: |
| 184 | self.y = range(len(z)) |
| 185 | if annotation_text is not None: |
| 186 | self.annotation_text = annotation_text |
| 187 | else: |
| 188 | self.annotation_text = self.z |
| 189 | self.colorscale = colorscale |
| 190 | self.reversescale = reversescale |
| 191 | self.font_colors = font_colors |
| 192 | |
| 193 | if np and isinstance(self.z, np.ndarray): |
| 194 | self.zmin = np.amin(self.z) |
| 195 | self.zmax = np.amax(self.z) |
| 196 | else: |
| 197 | self.zmin = min([v for row in self.z for v in row]) |
| 198 | self.zmax = max([v for row in self.z for v in row]) |
| 199 | |
| 200 | if kwargs.get("zmin", None) is not None: |
| 201 | self.zmin = kwargs["zmin"] |
| 202 | if kwargs.get("zmax", None) is not None: |
| 203 | self.zmax = kwargs["zmax"] |
| 204 | |
| 205 | self.zmid = (self.zmax + self.zmin) / 2 |
| 206 | |
| 207 | if kwargs.get("zmid", None) is not None: |
| 208 | self.zmid = kwargs["zmid"] |
| 209 | |
| 210 | def get_text_color(self): |
| 211 | """ |
| 212 | Get font color for annotations. |
| 213 | |
| 214 | The annotated heatmap can feature two text colors: min_text_color and |
| 215 | max_text_color. The min_text_color is applied to annotations for |
| 216 | heatmap values < (max_value - min_value)/2. The user can define these |
| 217 | two colors. Otherwise the colors are defined logically as black or |
| 218 | white depending on the heatmap's colorscale. |
| 219 | |
| 220 | :rtype (string, string) min_text_color, max_text_color: text |
| 221 | color for annotations for heatmap values < |
| 222 | (max_value - min_value)/2 and text color for annotations for |
| 223 | heatmap values >= (max_value - min_value)/2 |
| 224 | """ |
| 225 | # Plotly colorscales ranging from a lighter shade to a darker shade |
no outgoing calls
no test coverage detected