pmpl.formatters

Axis-level formatting functions for matplotlib.

Axis-level formatting utilities for matplotlib plots.

These functions allow you to format existing axes objects directly, without using context managers or changing global rcParams.

pmpl.formatters.format_horizontal(ax, grid=True, grid_alpha=0.3, **spine_kwargs)[source]

Format an axis for horizontal plots (e.g., horizontal bar charts).

Shows only the left spine with vertical gridlines.

Parameters:
  • ax (Axes) – The matplotlib Axes object to format

  • grid (bool) – Whether to show gridlines

  • grid_alpha (float) – Transparency of gridlines (0-1)

  • **spine_kwargs (Any) – Additional kwargs passed to spine configuration

Return type:

Axes

Returns:

The formatted Axes object (for chaining)

Example

>>> import matplotlib.pyplot as plt
>>> import pmpl
>>> fig, ax = plt.subplots()
>>> ax.barh(['A', 'B', 'C'], [1, 2, 3])
>>> pmpl.format_horizontal(ax)
>>> plt.show()
pmpl.formatters.format_vertical(ax, grid=True, grid_alpha=0.3, **spine_kwargs)[source]

Format an axis for vertical plots (e.g., line charts, bar charts).

Shows only the bottom spine with horizontal gridlines.

Parameters:
  • ax (Axes) – The matplotlib Axes object to format

  • grid (bool) – Whether to show gridlines

  • grid_alpha (float) – Transparency of gridlines (0-1)

  • **spine_kwargs (Any) – Additional kwargs passed to spine configuration

Return type:

Axes

Returns:

The formatted Axes object (for chaining)

Example

>>> import matplotlib.pyplot as plt
>>> import pmpl
>>> fig, ax = plt.subplots()
>>> ax.plot([1, 2, 3], [1, 4, 2])
>>> pmpl.format_vertical(ax)
>>> plt.show()
pmpl.formatters.format_base(ax, grid=True, grid_axis='y', grid_alpha=0.3)[source]

Apply base formatting to an axis (no spines, customizable grid).

Parameters:
  • ax (Axes) – The matplotlib Axes object to format

  • grid (bool) – Whether to show gridlines

  • grid_axis (str) – Which axis to show gridlines on (‘x’, ‘y’, or ‘both’)

  • grid_alpha (float) – Transparency of gridlines (0-1)

Return type:

Axes

Returns:

The formatted Axes object (for chaining)

Example

>>> import matplotlib.pyplot as plt
>>> import pmpl
>>> fig, ax = plt.subplots()
>>> ax.scatter([1, 2, 3], [1, 4, 2])
>>> pmpl.format_base(ax, grid_axis='both')
>>> plt.show()