def _write_annotations(self, mesh: mpl_collections.Collection, ax: plt.Axes) -> None: """Writes annotations to the center of cells. Internal.""" for path, facecolor in zip(mesh.get_paths(), mesh.get_facecolors()): # Calculate the center of the cell, assuming that it is a square # centered at (x=col, y=row). vertices = path.vertices[:4] row = int(round(np.mean([v[1] for v in vertices]))) col = int(round(np.mean([v[0] for v in vertices]))) annotation = self.annot_map.get((row, col), '') if not annotation: continue face_luminance = 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.annot_kwargs) ax.text(col, row, annotation, **text_kwargs)
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)