plots.style

plots.style

Print-oriented styling parameters for the plots modules.

The values here are the ones the spot* manuscripts render with. They are offered as plain data and as one dict-returning helper, never as a side effect: importing this module changes nothing, and no plotting function in spotforecast2.plots reads it. Applying a theme stays an explicit act of the caller, which is what keeps the plot functions composable with a caller’s own styling.

import matplotlib.pyplot as plt
from spotforecast2.plots.style import paper_rc

plt.rcParams.update(paper_rc())

Three separate jobs are served by three separate groups below, and they are not interchangeable. The ink tokens are chrome, the categorical hues carry entity identity, and the sequential ramp encodes magnitude.

Attributes

Name Description
CATEGORICAL Fixed-order hues for entities a figure singles out.
GRID Grid lines and neutral fills such as range bands.
INK Primary text and axis labels.
INK_MUTED Secondary text: tick labels, captions, de-emphasised entries.
RULE Axes edges and spines.
SEQUENTIAL_BLUE One hue, light to dark, for encoding magnitude.

Functions

Name Description
assign_colors Map every entry to a color, singling out highlight.
paper_rc Return matplotlib.rcParams overrides for the print look.

assign_colors

plots.style.assign_colors(entries, highlight=(), *, base=INK_MUTED)

Map every entry to a color, singling out highlight.

Entries named in highlight take the categorical hues in the order they are listed, and every other entry takes base. Passing a mapping instead pins chosen entries to chosen colors, which is what a document wants when one entity should keep its color across figures that contain different entries.

Parameters

Name Type Description Default
entries Iterable[str] Entry ids appearing in the figure. required
highlight Iterable[str] | Mapping[str, str] Either entry ids to draw from CATEGORICAL in order, or a mapping of entry id to an explicit color. ()
base str Color for entries not highlighted. INK_MUTED

Returns

Name Type Description
dict[str, str] A mapping of every entry id to a color.

Raises

Name Type Description
ValueError If more entries are highlighted than CATEGORICAL has hues.

Examples

from spotforecast2.plots.style import assign_colors

palette = assign_colors(
    ["team_a", "team_b", "baseline"], ["team_a", "baseline"]
)
print(palette["team_a"], palette["team_b"])
#2a78d6 #52514e

paper_rc

plots.style.paper_rc(dpi=200, font_size=8.5)

Return matplotlib.rcParams overrides for the print look.

The caller applies them, typically once per document: plt.rcParams.update(paper_rc()). Nothing in this package applies them implicitly.

Parameters

Name Type Description Default
dpi float Resolution for both on-screen figures and saved files. 200
font_size float Base font size in points. Tick and label sizes that a plot function sets explicitly are unaffected. 8.5

Returns

Name Type Description
dict[str, object] A mapping suitable for matplotlib.rcParams.update.

Examples

from spotforecast2.plots.style import paper_rc

rc = paper_rc(font_size=9)
print(rc["font.size"], rc["axes.edgecolor"])
9 #c9c8c2