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:
- Return type:
- 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:
- Return type:
- 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:
- Return type:
- 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()