srvar.theme

Visual grammar and theme management for srvar plots.

This module provides a consistent visual style across all srvar plotting functions, with semantic colour names, typography settings, and layout constants.

Usage

>>> from srvar.theme import srvar_style, get_color
>>> with srvar_style():
...     fig, ax = plt.subplots()
...     ax.plot(x, y, color=get_color("forecast"))
>>> from srvar.theme import apply_srvar_style
>>> apply_srvar_style()  # Apply globally
class srvar.theme.Layout(figure_single=(7.0, 3.5), figure_wide=(10.0, 4.0), figure_square=(5.0, 5.0), figure_panel=(10.0, 8.0), line_data=1.5, line_median=2.0, line_reference=1.0, line_grid=0.5, marker_size=4.0, band_alpha=0.2, fill_alpha=0.7, bar_alpha=0.75, legend_frameon=False, tight_layout_pad=0.5, dpi_display=150, dpi_save=300)[source]

Bases: object

Layout constants for srvar plots.

figure_single

Default figure size for single plots.

Type:

tuple[float, float]

figure_wide

Figure size for wide plots.

Type:

tuple[float, float]

figure_square

Figure size for square plots.

Type:

tuple[float, float]

figure_panel

Figure size for multi-panel layouts.

Type:

tuple[float, float]

line_data

Line width for data series.

Type:

float

line_median

Line width for median/summary lines.

Type:

float

line_reference

Line width for reference lines.

Type:

float

line_grid

Line width for grid lines.

Type:

float

marker_size

Default marker size.

Type:

float

band_alpha

Transparency for uncertainty bands.

Type:

float

fill_alpha

Transparency for filled regions.

Type:

float

bar_alpha

Transparency for bar plots.

Type:

float

legend_frameon

Whether to show legend frame.

Type:

bool

tight_layout_pad

Padding for tight_layout.

Type:

float

dpi_display

DPI for display.

Type:

int

dpi_save

DPI for saved figures.

Type:

int

class srvar.theme.Palette(observed='#2E86AB', shadow='#A23B72', forecast='#F18F01', volatility='#C73E1D', inclusion='#6B4226', coverage='#2E86AB', pit='#2E86AB', crps='#1B998B', band_fill='#2E86AB', reference='#888888', grid='#E0E0E0', spine='#333333', text='#1A1A1A')[source]

Bases: object

Colour palette for srvar plots.

observed

Colour for observed data series.

Type:

str

shadow

Colour for shadow/latent series.

Type:

str

forecast

Colour for forecast visualisations.

Type:

str

volatility

Colour for stochastic volatility plots.

Type:

str

inclusion

Colour for SSVS inclusion probability plots.

Type:

str

coverage

Colour for coverage plot lines.

Type:

str

pit

Colour for PIT histogram bars.

Type:

str

crps

Colour for CRPS line plots.

Type:

str

band_fill

Base colour for uncertainty bands (alpha applied separately).

Type:

str

reference

Colour for reference/nominal lines.

Type:

str

grid

Colour for grid lines.

Type:

str

spine

Colour for axis spines.

Type:

str

text

Colour for text elements.

Type:

str

property sequential: list[str]

Sequential palette for multiple series.

class srvar.theme.Theme(palette=<factory>, typography=<factory>, layout=<factory>, name='default')[source]

Bases: object

Complete theme specification for srvar plots.

A theme combines palette, typography, and layout settings into a single configuration that can be applied to all plots.

palette

Colour palette settings.

Type:

Palette

typography

Font and text settings.

Type:

Typography

layout

Figure size and layout settings.

Type:

Layout

name

Theme name for identification.

Type:

str

Examples

>>> theme = Theme()  # Default theme
>>> with srvar_style(theme):
...     fig, ax = plt.subplots()
>>> custom_theme = Theme(
...     palette=Palette(observed="#000000"),
...     typography=Typography(title_size=12.0),
... )
to_rcparams()[source]

Convert theme to matplotlib rcParams dictionary.

Returns:

Dictionary suitable for plt.rcParams.update().

Return type:

dict[str, Any]

class srvar.theme.Typography(family='sans-serif', title_size=11.0, label_size=9.0, tick_size=8.0, legend_size=8.0, annotation_size=7.5, title_weight='semibold', label_weight='normal')[source]

Bases: object

Font settings for srvar plots.

family

Font family.

Type:

str

title_size

Font size for plot titles.

Type:

float

label_size

Font size for axis labels.

Type:

float

tick_size

Font size for tick labels.

Type:

float

legend_size

Font size for legend text.

Type:

float

annotation_size

Font size for annotations.

Type:

float

title_weight

Font weight for titles.

Type:

str

label_weight

Font weight for labels.

Type:

str

srvar.theme.apply_srvar_style(theme=None)[source]

Globally apply srvar style to matplotlib.

This modifies matplotlib’s global rcParams. Use with caution in shared environments.

Parameters:

theme (Theme | None) – Theme to apply. If None, uses DEFAULT_THEME.

Return type:

None

Examples

>>> from srvar.theme import apply_srvar_style
>>> apply_srvar_style()  # All subsequent plots use srvar style
srvar.theme.get_alpha(name='band', theme=None)[source]

Get an alpha/transparency value by name.

Parameters:
  • name (str) – Alpha name: ‘band’, ‘fill’, or ‘bar’.

  • theme (Theme | None) – Theme to use. If None, uses DEFAULT_THEME.

Returns:

Alpha value between 0 and 1.

Return type:

float

srvar.theme.get_color(name, theme=None)[source]

Get a semantic colour by name.

Parameters:
  • name (str) – Colour name (e.g., ‘observed’, ‘shadow’, ‘forecast’, ‘volatility’).

  • theme (Theme | None) – Theme to use. If None, uses DEFAULT_THEME.

Returns:

Hex colour code.

Return type:

str

Examples

>>> get_color("forecast")
'#F18F01'
>>> get_color("shadow", COLORBLIND_THEME)
'#DC267F'
srvar.theme.get_figsize(name='single', theme=None)[source]

Get a figure size by name.

Parameters:
  • name (str) – Size name: ‘single’, ‘wide’, ‘square’, or ‘panel’.

  • theme (Theme | None) – Theme to use. If None, uses DEFAULT_THEME.

Returns:

Figure size (width, height) in inches.

Return type:

tuple[float, float]

Examples

>>> get_figsize("wide")
(10.0, 4.0)
srvar.theme.get_linewidth(name='data', theme=None)[source]

Get a line width by name.

Parameters:
  • name (str) – Line width name: ‘data’, ‘median’, ‘reference’, or ‘grid’.

  • theme (Theme | None) – Theme to use. If None, uses DEFAULT_THEME.

Returns:

Line width in points.

Return type:

float

srvar.theme.reset_style()[source]

Reset matplotlib to default style.

This is useful after calling apply_srvar_style() to restore defaults.

Return type:

None

srvar.theme.srvar_style(theme=None)[source]

Context manager to apply srvar visual style.

Parameters:

theme (Theme | None) – Theme to apply. If None, uses DEFAULT_THEME.

Yields:

Theme – The applied theme.

Return type:

Generator[Theme, None, None]

Examples

>>> with srvar_style():
...     fig, ax = plt.subplots()
...     ax.plot(x, y)
>>> with srvar_style(COLORBLIND_THEME):
...     fig, ax = plt.subplots()