def _write_annotations( self, centers_and_annot: List[Tuple[Point, Optional[str]]], collection: mpl_collections.Collection, ax: plt.Axes, ) -> None: """Writes annotations to the center of cells. Internal.""" for (center, annotation), facecolor in zip(centers_and_annot, collection.get_facecolors()): # Calculate the center of the cell, assuming that it is a square # centered at (x=col, y=row). if not annotation: continue x, y = center face_luminance = vis_utils.relative_luminance(facecolor) text_color = 'black' if face_luminance > 0.4 else 'white' text_kwargs = dict(color=text_color, ha="center", va="center") text_kwargs.update(self._config.get('annotation_text_kwargs', {})) ax.text(x, y, annotation, **text_kwargs)
def relative_luminance(color: np.ndarray) -> float: return vis_utils.relative_luminance(color)