def _write_annotations(
        self,
        centers_and_annot: list[tuple[Point, str | None]],
        collection: mpl_collections.Collection,
        ax: plt.Axes,
    ) -> None:
        """Writes annotations to the center of cells. Internal."""
        face_colors = cast(np.ndarray, collection.get_facecolor())
        for (center, annotation), facecolor in zip(centers_and_annot, face_colors):
            # 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[str, Any] = dict(color=text_color, ha="center", va="center")
            text_kwargs.update(self._config.get('annotation_text_kwargs', {}))
            ax.text(x, y, annotation, **text_kwargs)
Writes annotations to the center of cells. Internal.
cirq-core/cirq/vis/heatmap.py