"""Add a logo image as an inset axes header to a matplotlib figure.""" from __future__ import annotations from typing import TYPE_CHECKING if TYPE_CHECKING: import numpy as np from matplotlib.figure import Figure def add_header_logo( fig: "Figure", image: "np.ndarray", x: float = 0.88, y: float = 0.905, width: float = 0.08, height: float = 0.08, ) -> None: """Add a logo image as an inset axes in the upper-right area of a figure. Creates a new axes at the given figure coordinates and renders the image with axis lines and ticks hidden. Suitable for branding in report pages. Args: fig: The matplotlib Figure to add the logo to. image: Image array (H x W x C) as numpy ndarray, e.g. loaded with matplotlib.image.imread or PIL. x: Left edge of the logo axes in figure coordinates (0-1). y: Bottom edge of the logo axes in figure coordinates (0-1). width: Width of the logo axes in figure coordinates (0-1). height: Height of the logo axes in figure coordinates (0-1). """ ax_logo = fig.add_axes([x, y, width, height]) ax_logo.imshow(image) ax_logo.axis("off")