registry Module#
Theme registry and management for Episia.
This module maintains the global theme state and provides functions for getting/setting themes, retrieving color palettes, and registering custom themes.
Functions#
- episia.viz.themes.registry.set_theme(theme)[source]#
Set the active Episia theme globally.
Applies the Matplotlib style if available silently skips if matplotlib.style is unavailable in the current environment.
- Parameters:
theme (str) – One of ‘scientific’, ‘minimal’, ‘dark’, ‘colorblind’.
- Raises:
ValueError – Unknown theme name.
- Return type:
None
- episia.viz.themes.registry.get_theme()[source]#
Return the currently active theme name.
- Return type:
- episia.viz.themes.registry.get_available_themes()[source]#
Return list of all available theme names.
- episia.viz.themes.registry.get_palette(theme=None)[source]#
Return the colour palette for a given theme (or the active theme).
- episia.viz.themes.registry.get_plotly_layout(theme=None)[source]#
Return a base Plotly layout dict for a given theme.
Intended for use inside plotly_plotter provides consistent background colours and font colours per theme.
- episia.viz.themes.registry.apply_mpl_theme(theme=None)[source]#
Apply Matplotlib style for the given (or active) theme.
Called automatically by MatplotlibPlotter before each plot. Can be called manually to affect any subsequent plt calls.
- Parameters:
theme (str | None) – Theme name. Defaults to active theme.
- Return type:
None
- episia.viz.themes.registry.register_theme(name, palette, mplstyle_path=None, bg_paper='#ffffff', bg_plot='#ffffff', font_color='#222222')[source]#
Register a custom theme at runtime.
- Parameters:
- Raises:
ValueError – palette has fewer than 4 colours.
- Return type:
None
Example:
register_theme( "xcept", palette=["#0d6efd", "#dc3545", "#198754", "#ffc107"], bg_paper="#f8f9fa", ) set_theme("xcept")
Data#
Built-in Themes#
Theme Name |
Description |
Use Case |
|---|---|---|
|
Clean, high-contrast |
Default, general purpose |
|
No grid, maximum whitespace |
Minimalist dashboards |
|
Dark background |
Night mode, presentations |
|
Accessible palette |
Colorblind-safe publications |
Examples#
Basic theme usage:
from episia.viz.themes import set_theme, get_available_themes
# Check available themes
print(get_available_themes())
# ['scientific', 'minimal', 'dark', 'colorblind']
# Set theme globally
set_theme("dark")
# All subsequent plots will use dark theme
fig = plot_epicurve(result) # Uses dark theme
# Get current theme
current = get_theme()
print(current) # 'dark'
Getting color palettes:
from episia.viz.themes import get_palette
# Get palette for specific theme
colors = get_palette("colorblind")
print(colors)
# ['#0072B2', '#E69F00', '#56B4E9', '#009E73', '#F0E442', '#D55E00', ...]
# Use in custom plots
import matplotlib.pyplot as plt
for i, color in enumerate(colors[:3]):
plt.plot(x, y[i], color=color)
Registering custom themes:
from episia.viz.themes import register_theme, set_theme
# Register institutional theme
register_theme(
name="xcept_health",
palette=["#0d6efd", "#dc3545", "#198754", "#ffc107", "#6c757d"],
mplstyle_path="/path/to/custom.mplstyle", # optional
bg_paper="#f8f9fa",
bg_plot="#ffffff",
font_color="#212529"
)
# Use it immediately
set_theme("xcept_health")
Applying theme manually:
from episia.viz.themes import apply_mpl_theme
# Apply theme to current matplotlib session
apply_mpl_theme("scientific")
# All subsequent matplotlib commands use the theme
import matplotlib.pyplot as plt
plt.plot(x, y) # Uses scientific theme styling
Plotly layout extraction:
from episia.viz.themes import get_plotly_layout
# Get base layout dict for theme
layout = get_plotly_layout("minimal")
# Use in custom Plotly figures
import plotly.graph_objects as go
fig = go.Figure(data=data, layout=layout)