Coverage for python/lsst/analysis/tools/actions/plot/elements/plotInfoElement.py: 53%
17 statements
« prev ^ index » next coverage.py v7.5.1, created at 2024-05-16 04:37 -0700
« prev ^ index » next coverage.py v7.5.1, created at 2024-05-16 04:37 -0700
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 typing import TYPE_CHECKING, Any, Mapping
28import matplotlib.transforms as transforms
30from ....interfaces import PlotElement
31from ..plotUtils import parsePlotInfo
33if TYPE_CHECKING: 33 ↛ 34line 33 didn't jump to line 34, because the condition on line 33 was never true
34 from matplotlib.axes import Axes
37class PlotInfoElement(PlotElement):
38 """Adds information to a plot, such as run collection name,
39 datasets used, dataset type, and tract/visit IDs.
41 Notes
42 -----
43 Converts a plotInfo dict to a string and creates a textbox to display it.
45 """
47 def __call__(self, ax: Axes, figureInfo: Mapping[str, Any], **kwargs) -> Axes:
48 """Draw a text box that displays useful information about the plot.
50 Parameters
51 ----------
52 ax : `~matplotlib.axes.Axes`
53 Axes to plot on.
54 figInfo: `dict`
55 A dictionary containing information about the figure on which the
56 element is being placed. It should have the following keys:
58 ``"figsize"``
59 The width and height of the figure in inches
60 (`tuple` of two `float`s)
61 ``"dpi"``
62 The dpi of the figure (`float`)
64 Notes
65 -----
66 plotInfoElement is added to the figure in-place, so no parameter is
67 returned.
68 """
69 plotInfo = kwargs["plotInfo"]
70 plotInfoText = parsePlotInfo(plotInfo)
72 # Ensures consistent spacing between the plotName and plotInfoText:
73 dpi_scale_trans = transforms.Affine2D().scale(figureInfo["dpi"])
74 trans = ax.transAxes + transforms.ScaledTranslation(0.0, -0.28, dpi_scale_trans)
76 ax.set_axis_off()
77 ax.text(0, 1.0, plotInfo["plotName"], fontsize=7, ha="left", va="bottom")
78 ax.text(0, 1.0, plotInfoText, fontsize=6, alpha=0.6, ha="left", transform=trans)