Coverage for python / lsst / analysis / tools / actions / plot / elements / histElement.py: 86%
14 statements
« prev ^ index » next coverage.py v7.13.5, created at 2026-05-07 08:53 +0000
« prev ^ index » next coverage.py v7.13.5, created at 2026-05-07 08:53 +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__ = ("HistElement",)
26from typing import TYPE_CHECKING
28from lsst.pex.config import Field
30from ....interfaces import PlotElement
32if TYPE_CHECKING:
33 from matplotlib.axes import Axes
35 from lsst.analysis.tools.interfaces import KeyedData
38class HistElement(PlotElement):
39 """Configuration options for ax.hist elements.
41 Attributes
42 ----------
43 valsKey : `~lsst.pex.config.Field`
44 Y-axis data vector key.
45 bins : `~lsst.pex.config.Field`
46 Number of x axis bins within plot x-range.
47 color : `~lsst.pex.config.Field`
48 Color.
49 density : `~lsst.pex.config.Field`
50 If True, draw and return a probability density.
51 cumulative : `~lsst.pex.config.Field`
52 If True, draw a cumulative histogram of the data. If ``density`` is
53 also True, the histogram is normalized such that the last bin equals 1.
54 """
56 valsKey = Field[str](
57 doc="Y-axis data vector key.",
58 default="value",
59 )
60 bins = Field[int](
61 doc="Number of x axis bins within plot x-range.",
62 default=50,
63 )
64 color = Field[str](
65 doc="Color",
66 optional=True,
67 )
68 density = Field[bool](
69 doc="If True, draw and return a probability density.",
70 default=False,
71 )
72 cumulative = Field[bool](
73 doc="If True, draw a cumulative histogram of the data. If ``density`` "
74 "is also True, the histogram is normalized such that the last bin "
75 "equals 1.",
76 default=False,
77 )
79 def __call__(self, data: KeyedData, ax: Axes, **kwargs) -> KeyedData:
80 """Plot y versus x as lines and/or markers.
82 Parameters
83 ----------
84 data : `~lsst.analysis.tools.interfaces.KeyedData`
85 Keyed data containing the data to plot.
86 ax : `~matplotlib.axes.Axes`
87 Axes to plot on.
89 Returns
90 -------
91 data : `~lsst.analysis.tools.interfaces.KeyedData`
92 Data used for plotting.
93 """
94 ax.hist(
95 x=data[self.valsKey], # type: ignore
96 bins=self.bins,
97 color=self.color,
98 density=self.density,
99 cumulative=self.cumulative,
100 )
102 return data