visualization.themes

Visualization Themes Module

This module provides a framework for managing visualization themes in Optiland. It allows users to switch between different visual styles for plots, ensuring a consistent and customizable appearance. The framework is designed to be extensible, allowing for the creation of new themes and the modification of existing ones.

The core components of this module are: - The Theme class, which encapsulates all styling parameters. - A registry of predefined themes, such as ‘light’ and ‘dark’. - A global state that holds the currently active theme. - Functions to set the global theme and to use themes temporarily via a

context manager.

This system is inspired by matplotlib’s rcParams, but with a more structured, theme-based approach.

Kramer Harrison, 2025

Functions

get_active_theme()

Return a copy of the active theme.

list_themes()

Return a list of available theme names.

register_theme(name, theme)

Register a new theme.

set_theme(theme)

Set the global theme for all plots.

theme_context(theme)

A context manager to temporarily set the theme.

Classes

Theme(name, description, palette, **kwargs)

A class that defines the visual parameters for Optiland plots.

class Theme(name: str, description: str, palette: dict, **kwargs)[source]

A class that defines the visual parameters for Optiland plots.

classmethod from_dict(theme_dict: dict) Theme[source]

Create a Theme object from a dictionary.

to_dict()[source]

Return a dictionary representation of the theme.

get_active_theme() Theme[source]

Return a copy of the active theme.

list_themes() list[str][source]

Return a list of available theme names.

register_theme(name: str, theme: Theme)[source]

Register a new theme.

Parameters:
  • name – The name of the theme.

  • theme – The Theme object to register.

Raises:

ValueError – If a theme with the same name already exists.

set_theme(theme: str | Theme)[source]

Set the global theme for all plots.

Parameters:

theme – The theme to set. Can be a string identifier (e.g., ‘light’, ‘dark’, ‘solarized_light’, ‘solarized_dark’) or a Theme object.

Raises:
  • ValueError – If the theme identifier is not found.

  • TypeError – If the theme is not a string or a Theme object.

theme_context(theme: str | Theme)[source]

A context manager to temporarily set the theme.

This is useful for applying a theme to a specific block of code without changing the global theme.

Parameters:

theme – The theme to set. Can be a string identifier (e.g., ‘light’, ‘dark’, ‘solarized_light’, ‘solarized_dark’) or a Theme object.