@@ -189,6 +189,23 @@ def __init__(
189
189
self .reversescale = reversescale
190
190
self .font_colors = font_colors
191
191
192
+ if np and isinstance (self .z , np .ndarray ):
193
+ self .zmin = np .amin (self .z )
194
+ self .zmax = np .amax (self .z )
195
+ else :
196
+ self .zmin = min ([v for row in self .z for v in row ])
197
+ self .zmax = max ([v for row in self .z for v in row ])
198
+
199
+ if kwargs .get ("zmin" , None ) is not None :
200
+ self .zmin = kwargs ["zmin" ]
201
+ if kwargs .get ("zmax" , None ) is not None :
202
+ self .zmax = kwargs ["zmax" ]
203
+
204
+ self .zmid = (self .zmax + self .zmin ) / 2
205
+
206
+ if kwargs .get ("zmid" , None ) is not None :
207
+ self .zmid = kwargs ["zmid" ]
208
+
192
209
def get_text_color (self ):
193
210
"""
194
211
Get font color for annotations.
@@ -264,21 +281,6 @@ def get_text_color(self):
264
281
max_text_color = black
265
282
return min_text_color , max_text_color
266
283
267
- def get_z_mid (self ):
268
- """
269
- Get the mid value of z matrix
270
-
271
- :rtype (float) z_avg: average val from z matrix
272
- """
273
- if np and isinstance (self .z , np .ndarray ):
274
- z_min = np .amin (self .z )
275
- z_max = np .amax (self .z )
276
- else :
277
- z_min = min ([v for row in self .z for v in row ])
278
- z_max = max ([v for row in self .z for v in row ])
279
- z_mid = (z_max + z_min ) / 2
280
- return z_mid
281
-
282
284
def make_annotations (self ):
283
285
"""
284
286
Get annotations for each cell of the heatmap with graph_objs.Annotation
@@ -287,11 +289,10 @@ def make_annotations(self):
287
289
the heatmap
288
290
"""
289
291
min_text_color , max_text_color = _AnnotatedHeatmap .get_text_color (self )
290
- z_mid = _AnnotatedHeatmap .get_z_mid (self )
291
292
annotations = []
292
293
for n , row in enumerate (self .z ):
293
294
for m , val in enumerate (row ):
294
- font_color = min_text_color if val < z_mid else max_text_color
295
+ font_color = min_text_color if val < self . zmid else max_text_color
295
296
annotations .append (
296
297
graph_objs .layout .Annotation (
297
298
text = str (self .annotation_text [n ][m ]),
0 commit comments