Style Management

Helpers for discovering and applying the packaged matplotlib styles. The Style manager reads asset/mplstyle, provides preset combinations (scientific, report, minimal, presentation, poster, web, dark, and Korean variants), resets rcParams, and stacks multiple style files when needed.

Typical usage

import dartwork_mpl as dm

# Apply a preset (recommended)
dm.style.use("scientific")       # papers
dm.style.use("report")           # reports & dashboards
dm.style.use("minimal")          # Tufte-style, data-ink focus
dm.style.use("presentation")     # slides
dm.style.use("poster")           # conference posters
dm.style.use("web")              # web pages & documentation
dm.style.use("dark")             # dark backgrounds
dm.style.use("presentation-kr")  # Korean font variant

# Stack multiple styles for advanced customization
dm.style.stack(["base", "font-report", "theme-dark"])

# Inspect what a style will set
available = dm.list_styles()
style_dict = dm.load_style_dict("font-presentation")

API

Matplotlib style management utilities.

This module provides functions and classes for loading and applying matplotlib styles from the package’s built-in style library.

class dartwork_mpl.style.Style[source]

Bases: object

Class for managing and applying multiple matplotlib styles.

This class provides functionality for loading style presets and stacking multiple styles sequentially.

Examples

>>> import dartwork_mpl as dm
>>> dm.style.use("scientific")  # Apply a single preset
>>> dm.style.stack(["base", "lang-kr"])  # Stack multiple styles
context(preset_name: str, **kwargs: float | str) Iterator[None][source]

Context manager that temporarily applies a style within a code block.

Parameters:
  • preset_name (str) – Name of the preset to apply.

  • **kwargs (float | str) – Additional rcParams to override.

Examples

>>> with dm.style.context("dark"):
...     plt.plot([1, 2, 3])
load_presets() None[source]

Load style presets from the JSON file.

Reads presets.json and stores the configuration in the instance’s presets attribute.

presets_dict() dict[str, list[str]][source]

Return all available presets as a dictionary.

Returns:

Dictionary mapping preset names (keys) to their constituent style lists (values).

Return type:

dict[str, list[str]]

static presets_path() Path[source]

Get the path to the presets configuration file (presets.json).

Returns:

Path to the presets.json file containing combined style presets.

Return type:

Path

static stack(style_names: list[str]) None[source]

Stack multiple styles in order.

Applies multiple style files sequentially. Later styles override values set by earlier ones for the same keys.

Parameters:

style_names (list[str]) – List of style names to apply. Styles are applied in order, with later entries taking precedence.

Examples

>>> import dartwork_mpl as dm
>>> dm.style.stack(["base", "font-scientific", "lang-kr"])
use(preset_name: str | list[str], **kwargs: float | str) None[source]

Apply a preset style configuration or a list of presets.

This is the recommended way to apply styles in this module. Presets are pre-optimized combinations of styles for specific use cases.

Parameters:
  • preset_name (str or list of str) – Name of the preset to apply. Available presets: - “scientific”: Academic papers (default English) - “report”: Documents, reports, and dashboards - “minimal”: Tufte-style with minimal lines and ticks - “presentation”: Slide presentations - “poster”: Conference posters and large displays - “web”: Web pages and documentation - “dark”: Dark background theme - “scientific-kr”: Academic papers (Korean fonts) - “report-kr”: Reports and dashboards (Korean fonts) - “minimal-kr”: Minimal style (Korean fonts) - “presentation-kr”: Presentations (Korean fonts) - “poster-kr”: Conference posters (Korean fonts) - “web-kr”: Web pages (Korean fonts) - “dark-kr”: Dark theme (Korean fonts)

  • **kwargs (float | str) – Additional rcParams to override the preset defaults (e.g., font_size=12). Both underscore (font_size) and dot (font.size) notation are supported.

Raises:

KeyError – If the requested preset name is not found in the presets dictionary.

Examples

>>> import dartwork_mpl as dm
>>> dm.style.use("scientific")
>>> dm.style.use("presentation-kr", font_size=16)
>>> dm.style.use(["scientific", "dark"])  # Stack multiple presets
dartwork_mpl.style.list_styles() list[str][source]

Return a list of all available styles.

Returns:

List of style names.

Return type:

list[str]

dartwork_mpl.style.load_style_dict(name: str) dict[str, float | str][source]

Read key-value pairs from an mplstyle file.

Parameters:

name (str) – Name of the style to load.

Returns:

Dictionary of style parameters. Values are converted to float where possible; otherwise they are kept as strings.

Return type:

dict[str, float | str]

dartwork_mpl.style.style_path(name: str) Path[source]

Get the path to a style file.

Parameters:

name (str) – Name of the style (e.g., ‘report’, ‘scientific’).

Returns:

Absolute path to the style file (.mplstyle).

Return type:

Path

Raises:

ValueError – If the specified style name cannot be found.