Coverage for python / lsst / analysis / tools / actions / plot / elements / plotInfoElement.py: 56%
16 statements
« prev ^ index » next coverage.py v7.13.5, created at 2026-05-01 08:55 +0000
« prev ^ index » next coverage.py v7.13.5, created at 2026-05-01 08:55 +0000
1# This file is part of analysis_tools.
2#
3# Developed for the LSST Data Management System.
4# This product includes software developed by the LSST Project
5# (https://www.lsst.org).
6# See the COPYRIGHT file at the top-level directory of this distribution
7# for details of code ownership.
8#
9# This program is free software: you can redistribute it and/or modify
10# it under the terms of the GNU General Public License as published by
11# the Free Software Foundation, either version 3 of the License, or
12# (at your option) any later version.
13#
14# This program is distributed in the hope that it will be useful,
15# but WITHOUT ANY WARRANTY; without even the implied warranty of
16# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17# GNU General Public License for more details.
18#
19# You should have received a copy of the GNU General Public License
20# along with this program. If not, see <https://www.gnu.org/licenses/>.
22from __future__ import annotations
24__all__ = ("PlotInfoElement",)
26from collections.abc import Mapping
27from typing import TYPE_CHECKING, Any
29import matplotlib.transforms as transforms
31from ....interfaces import PlotElement
32from ..plotUtils import parsePlotInfo
34if TYPE_CHECKING:
35 from matplotlib.axes import Axes
38class PlotInfoElement(PlotElement):
39 """Adds information to a plot, such as run collection name,
40 datasets used, dataset type, and tract/visit IDs.
42 Notes
43 -----
44 Converts a plotInfo dict to a string and creates a textbox to display it.
46 """
48 def __call__(self, ax: Axes, figureInfo: Mapping[str, Any], **kwargs) -> Axes:
49 """Draw a text box that displays useful information about the plot.
51 Parameters
52 ----------
53 ax : `~matplotlib.axes.Axes`
54 Axes to plot on.
55 figInfo: `dict`
56 A dictionary containing information about the figure on which the
57 element is being placed. It should have the following keys:
59 ``"figsize"``
60 The width and height of the figure in inches
61 (`tuple` of two `float`s)
62 ``"dpi"``
63 The dpi of the figure (`float`)
65 Notes
66 -----
67 plotInfoElement is added to the figure in-place, so no parameter is
68 returned.
69 """
70 plotInfo = kwargs["plotInfo"]
71 plotInfoText = parsePlotInfo(plotInfo)
73 # Ensures consistent spacing between the plotName and plotInfoText:
74 dpi_scale_trans = transforms.Affine2D().scale(figureInfo["dpi"])
75 trans = ax.transAxes + transforms.ScaledTranslation(0.0, -0.28, dpi_scale_trans)
77 ax.set_axis_off()
78 ax.text(0, 1.0, plotInfo["plotName"], fontsize=7, ha="left", va="bottom")
79 ax.text(0, 1.0, plotInfoText, fontsize=6, alpha=0.6, ha="left", transform=trans)