Coverage for python/lsst/analysis/tools/actions/plot/elements/histElement.py: 74%

17 statements  

« prev     ^ index     » next       coverage.py v7.4.4, created at 2024-04-10 04:56 -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/>. 

21 

22from __future__ import annotations 

23 

24__all__ = ("HistElement",) 

25 

26from typing import TYPE_CHECKING 

27 

28from lsst.pex.config import Field 

29 

30from ....interfaces import PlotElement 

31 

32if TYPE_CHECKING: 32 ↛ 33line 32 didn't jump to line 33, because the condition on line 32 was never true

33 from lsst.analysis.tools.interfaces import KeyedData 

34 from matplotlib.axes import Axes 

35 

36 

37class HistElement(PlotElement): 

38 """Configuration options for ax.hist elements. 

39 

40 Attributes 

41 ---------- 

42 valsKey : `~lsst.pex.config.Field` 

43 Y-axis data vector key. 

44 bins : `~lsst.pex.config.Field` 

45 Number of x axis bins within plot x-range. 

46 color : `~lsst.pex.config.Field` 

47 Color. 

48 density : `~lsst.pex.config.Field` 

49 If True, draw and return a probability density. 

50 cumulative : `~lsst.pex.config.Field` 

51 If True, draw a cumulative histogram of the data. If ``density`` is 

52 also True, the histogram is normalized such that the last bin equals 1. 

53 """ 

54 

55 valsKey = Field[str]( 

56 doc="Y-axis data vector key.", 

57 default="value", 

58 ) 

59 bins = Field[int]( 

60 doc="Number of x axis bins within plot x-range.", 

61 default=50, 

62 ) 

63 color = Field[str]( 

64 doc="Color", 

65 optional=True, 

66 ) 

67 density = Field[bool]( 

68 doc="If True, draw and return a probability density.", 

69 default=False, 

70 ) 

71 cumulative = Field[bool]( 

72 doc="If True, draw a cumulative histogram of the data. If ``density`` " 

73 "is also True, the histogram is normalized such that the last bin " 

74 "equals 1.", 

75 default=False, 

76 ) 

77 

78 def __call__(self, data: KeyedData, ax: Axes, **kwargs) -> KeyedData: 

79 """Plot y versus x as lines and/or markers. 

80 

81 Parameters 

82 ---------- 

83 data : `~lsst.analysis.tools.interfaces.KeyedData` 

84 Keyed data containing the data to plot. 

85 ax : `~matplotlib.axes.Axes` 

86 Axes to plot on. 

87 

88 Returns 

89 ------- 

90 data : `~lsst.analysis.tools.interfaces.KeyedData` 

91 Data used for plotting. 

92 """ 

93 ax.hist( 

94 x=data[self.valsKey], # type: ignore 

95 bins=self.bins, 

96 color=self.color, 

97 density=self.density, 

98 cumulative=self.cumulative, 

99 ) 

100 

101 return data