Style Management

Helpers for discovering and applying the packaged matplotlib styles. The Style manager reads asset/mplstyle and preset combinations (scientific, investment, presentation, and Korean variants) from presets.json, resets rcParams, and stacks multiple style files when needed. Use the helpers below to apply a preset, stack multiple styles, or inspect what a preset changes before you commit it to a figure.

Style.use(preset_name) Applies a preset key from presets.json (e.g., "scientific", "investment", "presentation", "scientific-kr"). This is the recommended way to apply styles.

  • Parameters: - preset_name: string looked up in the presets mapping.

  • Returns: - None.

Style.stack(style_names) Stack multiple style files in order. Use this for advanced customization.

  • Parameters: - style_names: list/tuple of style stems; later styles override earlier ones.

  • Returns: - None.

list_styles() Lists every *.mplstyle file bundled with the package.

  • Parameters: - none.

  • Returns: - list[str] sorted by filename.

load_style_dict(name) Reads a single style file into a dict so you can inspect or tweak rcParams programmatically.

  • Parameters: - name: style stem.

  • Returns: - dict mapping rcParam keys to values.

Typical usage

import dartwork_mpl as dm

# Apply a preset (recommended)
dm.style.use("scientific")
dm.style.use("presentation-kr")

# Stack multiple styles for advanced customization
dm.style.stack(["base", "font-scientific", "lang-kr"])

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

Matplotlib style management utilities.

This module provides functions and classes for managing and applying matplotlib styles from the package’s style library.

class dartwork_mpl.style.Style[source]

Bases: object

A class for managing and applying multiple matplotlib styles.

This class provides functionality to load style presets and apply multiple styles in sequence.

Examples

>>> import dartwork_mpl as dm
>>> dm.style.use("scientific")  # Apply a preset
>>> dm.style.stack(["base", "lang-kr"])  # Stack multiple styles
load_presets() None[source]

Load style presets from the JSON file.

This method reads the presets.json file and stores the preset definitions in the instance’s presets attribute.

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

Get all available presets as a dictionary.

Returns:

Dictionary mapping preset names to their style configuration lists.

Return type:

dict[str, list[str]]

static presets_path() Path[source]

Get the path to the presets file.

Returns:

Path to the presets.json file containing style preset definitions.

Return type:

Path

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

Stack multiple styles in order.

This method applies multiple style files in sequence. Later styles override earlier ones for conflicting settings.

Parameters:

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

Examples

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

Apply a preset style configuration.

This is the recommended way to apply styles. Presets are predefined combinations of styles optimized for specific use cases.

Parameters:

preset_name (str) – Name of the preset to apply. Available presets: - “scientific”: For academic papers - “investment”: For investment reports - “presentation”: For presentations - “scientific-kr”: Scientific with Korean font - “investment-kr”: Investment with Korean font - “presentation-kr”: Presentation with Korean font

Raises:

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

Examples

>>> import dartwork_mpl as dm
>>> dm.style.use("scientific")
>>> dm.style.use("presentation-kr")
dartwork_mpl.style.list_styles() list[str][source]

List 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]

Load key, value pairs from a mplstyle file.

Parameters:

name (str) – Name of the style.

Returns:

Dictionary of style parameters. Values are converted to float if possible, otherwise 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.

Returns:

Path to the style file.

Return type:

Path

Raises:

ValueError – If the style is not found.