Coverage for python/lsst/utils/plotting/publication_plots.py: 100%
70 statements
« prev ^ index » next coverage.py v7.15.2, created at 2026-07-16 14:40 -0700
« prev ^ index » next coverage.py v7.15.2, created at 2026-07-16 14:40 -0700
1# This file is part of utils.
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# Use of this source code is governed by a 3-clause BSD-style
10# license that can be found in the LICENSE file.
11"""Utilities for making publication-quality figures."""
13__all__ = [
14 "accent_color",
15 "divergent_cmap",
16 "galaxies_cmap",
17 "galaxies_color",
18 "get_band_dicts",
19 "mk_colormap",
20 "set_rubin_plotstyle",
21 "sso_cmap",
22 "sso_color",
23 "stars_cmap",
24 "stars_color",
25]
27import numpy as np
29from . import (
30 get_multiband_plot_colors,
31 get_multiband_plot_linestyles,
32 get_multiband_plot_symbols,
33)
36def set_rubin_plotstyle() -> None:
37 """Set the matplotlib style for Rubin publications."""
38 from matplotlib import style
40 style.use("lsst.utils.plotting.rubin")
43def mk_colormap(colorNames): # type: ignore
44 """Make a colormap from the list of color names.
46 Parameters
47 ----------
48 colorNames : `list`
49 A list of strings that correspond to matplotlib named colors.
51 Returns
52 -------
53 cmap : `matplotlib.colors.LinearSegmentedColormap`
54 A colormap stepping through the supplied list of names.
55 """
56 from matplotlib import colors
58 blues = []
59 greens = []
60 reds = []
61 alphas = []
63 if len(colorNames) == 1:
64 # Alpha is between 0 and 1 really but
65 # using 1.5 saturates out the top of the
66 # colorscale, this looks good for ComCam data
67 # but might want to be changed in the future.
68 alphaRange = [0.2, 1.0]
69 nums = np.linspace(0, 1, len(alphaRange))
70 r, g, b = colors.colorConverter.to_rgb(colorNames[0])
71 for num, alpha in zip(nums, alphaRange):
72 blues.append((num, b, b))
73 greens.append((num, g, g))
74 reds.append((num, r, r))
75 alphas.append((num, alpha, alpha))
77 else:
78 nums = np.linspace(0, 1, len(colorNames))
79 if len(colorNames) == 3:
80 alphaRange = [1.0, 1.0, 1.0]
81 elif len(colorNames) == 5:
82 alphaRange = [1.0, 0.7, 0.3, 0.7, 1.0]
83 else:
84 alphaRange = np.ones(len(colorNames))
86 for num, color, alpha in zip(nums, colorNames, alphaRange):
87 r, g, b = colors.colorConverter.to_rgb(color)
88 blues.append((num, b, b))
89 greens.append((num, g, g))
90 reds.append((num, r, r))
91 alphas.append((num, alpha, alpha))
93 colorDict = {"blue": blues, "red": reds, "green": greens, "alpha": alphas}
94 cmap = colors.LinearSegmentedColormap("newCmap", colorDict)
95 return cmap
98def divergent_cmap(): # type: ignore
99 """Make a divergent color map.
101 Returns
102 -------
103 cmap : `matplotlib.colors.LinearSegmentedColormap`
104 A colormap stepping from the standard stars color through
105 gray to the accent color.
106 """
107 cmap = mk_colormap([stars_color(), "#D9DCDE", accent_color()])
109 return cmap
112def stars_cmap(single_color=False): # type: ignore
113 """Make a color map for stars.
115 Parameters
116 ----------
117 single_color : `bool`, optional
118 If `True` use the standard stars color.
120 Returns
121 -------
122 cmap : `matplotlib.colors.Colormap`
123 A colormap derived from the standard stars color if
124 ``single_color`` is `True`, otherwise the seaborn "mako" palette.
125 """
126 import seaborn as sns
127 from matplotlib.colors import ListedColormap
129 if single_color:
130 cmap = mk_colormap([stars_color()])
131 else:
132 cmap = ListedColormap(sns.color_palette("mako", 256))
133 return cmap
136def stars_color() -> str:
137 """Return the star color string for lines."""
138 return "#084d96"
141def accent_color() -> str:
142 """Return a contrasting color for overplotting.
144 Notes
145 -----
146 Black is the best for this but if you need two colors
147 this works well on blue.
148 """
149 return "#DE8F05"
152def galaxies_cmap(single_color: bool = False): # type: ignore
153 """Make a color map for galaxies.
155 Parameters
156 ----------
157 single_color : `bool`, optional
158 If `True` use the standard galaxies color.
160 Returns
161 -------
162 cmap : `matplotlib.colors.LinearSegmentedColormap` or `str`
163 A colormap derived from the standard galaxies color if
164 ``single_color`` is `True`, otherwise the colormap name "inferno".
165 """
166 if single_color:
167 cmap = mk_colormap([galaxies_color()])
168 else:
169 cmap = "inferno"
170 return cmap
173def galaxies_color() -> str:
174 """Return the galaxy color string for lines."""
175 return "#961A45"
178def sso_color() -> str:
179 """Return the SSO color string for lines."""
180 return "#01694c"
183def sso_cmap(single_color: bool = False): # type: ignore
184 """Make a color map for solar system objects.
186 Parameters
187 ----------
188 single_color : `bool`, optional
189 If `True` use the standard SSO color.
191 Returns
192 -------
193 cmap : `matplotlib.colors.LinearSegmentedColormap` or `str`
194 A colormap derived from the standard SSO color if
195 ``single_color`` is `True`, otherwise the colormap name "viridis".
196 """
197 if single_color:
198 cmap = mk_colormap([sso_color()])
199 else:
200 cmap = "viridis"
201 return cmap
204def get_band_dicts() -> dict:
205 """Define palettes, from RTN-045.
207 Returns
208 -------
209 band_dict : `dict` of `dict`
210 Dicts of colors, colors_black, symbols, and line_styles,
211 keyed on bands 'u', 'g', 'r', 'i', 'z', and 'y'.
213 Notes
214 -----
215 This includes dicts for colors (bandpass colors for white background),
216 colors_black (bandpass colors for black background), plot symbols, and
217 line_styles, keyed on band (ugrizy).
218 """
219 colors = get_multiband_plot_colors()
220 colors_black = get_multiband_plot_colors(dark_background=True)
221 symbols = get_multiband_plot_symbols()
222 line_styles = get_multiband_plot_linestyles()
224 return {
225 "colors": colors,
226 "colors_black": colors_black,
227 "symbols": symbols,
228 "line_styles": line_styles,
229 }