Coverage for python / lsst / utils / plotting / publication_plots.py: 16%
70 statements
« prev ^ index » next coverage.py v7.13.5, created at 2026-04-14 23:31 +0000
« prev ^ index » next coverage.py v7.13.5, created at 2026-04-14 23:31 +0000
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 """
38 Set the matplotlib style for Rubin publications
39 """
40 from matplotlib import style
42 style.use("lsst.utils.plotting.rubin")
45def mk_colormap(colorNames): # type: ignore
46 """Make a colormap from the list of color names.
48 Parameters
49 ----------
50 colorNames : `list`
51 A list of strings that correspond to matplotlib named colors.
53 Returns
54 -------
55 cmap : `matplotlib.colors.LinearSegmentedColormap`
56 A colormap stepping through the supplied list of names.
57 """
58 from matplotlib import colors
60 blues = []
61 greens = []
62 reds = []
63 alphas = []
65 if len(colorNames) == 1:
66 # Alpha is between 0 and 1 really but
67 # using 1.5 saturates out the top of the
68 # colorscale, this looks good for ComCam data
69 # but might want to be changed in the future.
70 alphaRange = [0.2, 1.0]
71 nums = np.linspace(0, 1, len(alphaRange))
72 r, g, b = colors.colorConverter.to_rgb(colorNames[0])
73 for num, alpha in zip(nums, alphaRange):
74 blues.append((num, b, b))
75 greens.append((num, g, g))
76 reds.append((num, r, r))
77 alphas.append((num, alpha, alpha))
79 else:
80 nums = np.linspace(0, 1, len(colorNames))
81 if len(colorNames) == 3:
82 alphaRange = [1.0, 1.0, 1.0]
83 elif len(colorNames) == 5:
84 alphaRange = [1.0, 0.7, 0.3, 0.7, 1.0]
85 else:
86 alphaRange = np.ones(len(colorNames))
88 for num, color, alpha in zip(nums, colorNames, alphaRange):
89 r, g, b = colors.colorConverter.to_rgb(color)
90 blues.append((num, b, b))
91 greens.append((num, g, g))
92 reds.append((num, r, r))
93 alphas.append((num, alpha, alpha))
95 colorDict = {"blue": blues, "red": reds, "green": greens, "alpha": alphas}
96 cmap = colors.LinearSegmentedColormap("newCmap", colorDict)
97 return cmap
100def divergent_cmap(): # type: ignore
101 """
102 Make a divergent color map.
103 """
104 cmap = mk_colormap([stars_color(), "#D9DCDE", accent_color()])
106 return cmap
109def stars_cmap(single_color=False): # type: ignore
110 """Make a color map for stars."""
111 import seaborn as sns
112 from matplotlib.colors import ListedColormap
114 if single_color:
115 cmap = mk_colormap([stars_color()])
116 else:
117 cmap = ListedColormap(sns.color_palette("mako", 256))
118 return cmap
121def stars_color() -> str:
122 """Return the star color string for lines"""
123 return "#084d96"
126def accent_color() -> str:
127 """Return a contrasting color for overplotting,
128 black is the best for this but if you need two colors
129 this works well on blue.
130 """
131 return "#DE8F05"
134def galaxies_cmap(single_color=False): # type: ignore
135 """Make a color map for galaxies."""
136 if single_color:
137 cmap = mk_colormap([galaxies_color()])
138 else:
139 cmap = "inferno"
140 return cmap
143def galaxies_color() -> str:
144 """Return the galaxy color string for lines"""
145 return "#961A45"
148def sso_color() -> str:
149 """Return the SSO color string for lines"""
150 return "#01694c"
153def sso_cmap(single_color=False): # type: ignore
154 """Make a color map for solar system objects."""
155 if single_color:
156 cmap = mk_colormap([sso_color()])
157 else:
158 cmap = "viridis"
159 return cmap
162def get_band_dicts() -> dict:
163 """
164 Define palettes, from RTN-045. This includes dicts for colors (bandpass
165 colors for white background), colors_black (bandpass colors for
166 black background), plot symbols, and line_styles, keyed on band (ugrizy).
168 Returns
169 -------
170 band_dict : `dict` of `dict`
171 Dicts of colors, colors_black, symbols, and line_styles,
172 keyed on bands 'u', 'g', 'r', 'i', 'z', and 'y'.
173 """
174 colors = get_multiband_plot_colors()
175 colors_black = get_multiband_plot_colors(dark_background=True)
176 symbols = get_multiband_plot_symbols()
177 line_styles = get_multiband_plot_linestyles()
179 return {
180 "colors": colors,
181 "colors_black": colors_black,
182 "symbols": symbols,
183 "line_styles": line_styles,
184 }