Coverage for python/lsst/analysis/tools/actions/plot/elements/scatterElement.py: 63%
23 statements
« prev ^ index » next coverage.py v7.5.0, created at 2024-04-27 04:18 -0700
« prev ^ index » next coverage.py v7.5.0, created at 2024-04-27 04:18 -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__ = ("ScatterElement",)
26from typing import TYPE_CHECKING
28from lsst.pex.config import Field
30from ....interfaces import PlotElement
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
37class ScatterElement(PlotElement):
38 """Configuration options for scatter plot plot elements.
40 Attributes
41 ----------
42 xKey : `~lsst.pex.config.Field`
43 X-axis data vector key. If None, the index of the values are used.
44 valsKey : `~lsst.pex.config.Field`
45 Y-axis data vector key. Plotted against the index if no xKey is given.
46 color : `~lsst.pex.config.Field`
47 Color.
48 marker : `~lsst.pex.config.Field`
49 Point marker.
50 linestyle : `~lsst.pex.config.Field`
51 Linestyle.
52 linewidth : `~lsst.pex.config.Field`
53 Linewidth.
54 markersize : `~lsst.pex.config.Field`
55 Markersize.
56 """
58 xKey = Field[str](
59 doc="X-axis data vector key. If None, the index of the values are used.",
60 optional=True,
61 )
62 valsKey = Field[str](
63 doc="Y-axis data vector key. Plotted against the index if no xKey is given.",
64 default="value",
65 )
66 color = Field[str](
67 doc="Color",
68 optional=True,
69 )
70 marker = Field[str](
71 doc="Point marker",
72 optional=True,
73 )
74 linestyle = Field[str](
75 doc="Linestyle",
76 optional=True,
77 )
78 linewidth = Field[float](
79 doc="Linewidth",
80 optional=True,
81 )
82 markersize = Field[float](
83 doc="Markersize",
84 optional=True,
85 )
87 def __call__(self, data: KeyedData, ax: Axes, **kwargs) -> KeyedData:
88 """Plot y versus x as lines and/or markers.
90 Parameters
91 ----------
92 data : `~lsst.analysis.tools.interfaces.KeyedData`
93 Keyed data containing the data to plot.
94 ax : `~matplotlib.axes.Axes`
95 Axes to plot on.
97 Returns
98 -------
99 data : `~lsst.analysis.tools.interfaces.KeyedData`
100 Data used for plotting.
101 """
102 self._validateInputs(data)
103 ax.plot(
104 data[self.xKey] if self.xKey is not None else range(len(data[self.valsKey])), # type: ignore
105 data[self.valsKey], # type: ignore
106 color=self.color if self.color is not None else None,
107 marker=self.marker if self.marker is not None else None,
108 linestyle=self.linestyle if self.linestyle is not None else None,
109 linewidth=self.linewidth if self.linewidth is not None else None,
110 markersize=self.markersize if self.markersize is not None else None,
111 )
113 return data
115 def _validateInputs(self, data: KeyedData) -> None:
116 """Validate inputs.
118 Parameters
119 ----------
120 data : `~lsst.analysis.tools.interfaces.KeyedData`
121 Data to plot.
122 """
123 if self.xKey is not None and len(data[self.xKey]) != len(data[self.valsKey]): # type: ignore
124 raise ValueError("X and Y vector inputs must be the same length.")