Skip to content

Plotting Styles

style

Style management for PrimeFeat plots.

Provides utilities for applying and managing matplotlib styles for publication-quality figures.

use_style(style='publication')

Apply a PrimeFeat plotting style.

PARAMETER DESCRIPTION
style

One of 'publication', 'presentation', or 'dark' - 'publication': Optimized for PRD two-column format (default) - 'presentation': Large fonts and bold lines for slides - 'dark': High contrast colors for dark backgrounds

DEFAULT: 'publication'

Examples:

>>> import primefeat.plots as plot
>>> plot.use_style('presentation')  # Switch to presentation mode
>>> plot.use_style('publication')   # Back to publication mode
Source code in src/primefeat/plots/style.py
def use_style(style="publication"):
    """
    Apply a PrimeFeat plotting style.

    Args:
        style: One of 'publication', 'presentation', or 'dark'
            - 'publication': Optimized for PRD two-column format (default)
            - 'presentation': Large fonts and bold lines for slides
            - 'dark': High contrast colors for dark backgrounds

    Examples:
        >>> import primefeat.plots as plot
        >>> plot.use_style('presentation')  # Switch to presentation mode
        >>> plot.use_style('publication')   # Back to publication mode
    """
    if style not in _AVAILABLE_STYLES:
        available = ", ".join(_AVAILABLE_STYLES.keys())
        raise ValueError(f"Style '{style}' not found. Available styles: {available}")

    style_path = _AVAILABLE_STYLES[style]
    if not style_path.exists():
        raise FileNotFoundError(f"Style file not found: {style_path}")

    plt.style.use(str(style_path))
    print_success(f"Applied '{style}' style")

style_context(style='publication')

Context manager for temporary style changes.

PARAMETER DESCRIPTION
style

One of 'publication', 'presentation', or 'dark'

DEFAULT: 'publication'

Examples:

>>> with plot.style_context('presentation'):
...     fig, ax = plt.subplots()
...     ax.plot(x, y)
... # Style automatically reverts after the block
Source code in src/primefeat/plots/style.py
@contextmanager
def style_context(style="publication"):
    """
    Context manager for temporary style changes.

    Args:
        style: One of 'publication', 'presentation', or 'dark'

    Examples:
        >>> with plot.style_context('presentation'):
        ...     fig, ax = plt.subplots()
        ...     ax.plot(x, y)
        ... # Style automatically reverts after the block
    """
    if style not in _AVAILABLE_STYLES:
        available = ", ".join(_AVAILABLE_STYLES.keys())
        raise ValueError(f"Style '{style}' not found. Available styles: {available}")

    style_path = _AVAILABLE_STYLES[style]
    if not style_path.exists():
        raise FileNotFoundError(f"Style file not found: {style_path}")

    with plt.style.context(str(style_path)):
        yield

list_styles()

List all available PrimeFeat styles.

RETURNS DESCRIPTION
dict

Dictionary of style names and descriptions

Source code in src/primefeat/plots/style.py
def list_styles():
    """
    List all available PrimeFeat styles.

    Returns:
        dict: Dictionary of style names and descriptions
    """
    styles = {
        "publication": 'Optimized for PRD two-column format (9pt fonts, 3.375" width)',
        "presentation": "Large fonts and bold lines for slides and posters",
        "dark": "High contrast colors for dark backgrounds and dark mode",
    }

    styles_table = Table(title="Available PrimeFeat Styles", show_header=True)
    styles_table.add_column("Status", justify="center", width=3)
    styles_table.add_column("Name", style="cyan", width=14)
    styles_table.add_column("Description", style="dim")

    for name, description in styles.items():
        status = (
            "[green]✓[/green]" if _AVAILABLE_STYLES[name].exists() else "[red]✗[/red]"
        )
        styles_table.add_row(status, name, description)

    console.print(styles_table)
    console.print("\n[cyan]Usage:[/cyan]")
    console.print("  [dim]import primefeat.plots as plot[/dim]")
    console.print("  [dim]plot.use_style('presentation')  # Switch styles[/dim]")
    console.print("  [dim]plot.use_style('publication')   # Default style[/dim]")

    return styles