pmpl.styles

Style application utilities for matplotlib.

Context managers for temporarily applying matplotlib styles.

pmpl.styles.style(preset='base', **overrides)[source]

Apply a matplotlib style temporarily within a context.

Parameters:
  • preset (str) – Name of the style preset to apply (‘base’, ‘horizontal’, ‘vertical’)

  • **overrides (Any) – Additional rcParams to override or extend the preset

Yields:

None

Raises:

ValueError – If the preset name is not recognized

Return type:

Generator[None, None, None]

Example

>>> import matplotlib.pyplot as plt
>>> import pmpl
>>> with pmpl.style('horizontal'):
...     fig, ax = plt.subplots()
...     ax.barh(['A', 'B', 'C'], [1, 2, 3])
...     plt.show()
pmpl.styles.set_defaults(preset='base', **overrides)[source]

Permanently set matplotlib rcParams to a preset style.

Unlike the context manager, this persists for the entire session until explicitly changed again.

Parameters:
  • preset (str) – Name of the style preset to apply (‘base’, ‘horizontal’, ‘vertical’)

  • **overrides (Any) – Additional rcParams to override or extend the preset

Raises:

ValueError – If the preset name is not recognized

Return type:

None

Example

>>> import pmpl
>>> pmpl.set_defaults('vertical')
>>> # All subsequent plots will use the vertical style