"""
Base Plotter Utilities
======================
This module defines ``BasePlotter``, a lightweight helper class that
standardizes figure creation and title placement across all diagnostics
plots in the ``ufs_da_diagnostics`` package.
It provides:
- Consistent Matplotlib styling (fonts, tick sizes, legend sizes)
- A unified ``new_figure()`` method with controlled margins
- A robust ``add_title()`` method using a dedicated title axis
All higher‑level plotters (increment maps, spectra, obs diagnostics,
ATMS diagnostics, QC plots, etc.) inherit or use this class to ensure
visual consistency across the entire diagnostics suite.
"""
import matplotlib.pyplot as plt
[docs]
class BasePlotter:
"""
Base class providing consistent figure styling and layout helpers.
This class configures global Matplotlib parameters for uniform
appearance across all diagnostics plots. It also provides helper
methods for creating figures with standardized margins and adding
top‑level titles using a dedicated axis.
Notes
-----
- ``plt.rcParams`` is updated at initialization to ensure consistent
font sizes and label formatting.
- ``new_figure()`` returns a figure with controlled margins suitable
for multi‑panel layouts.
- ``add_title()`` places a title in a fixed top region using an
invisible axis, ensuring stable spacing regardless of subplot
configuration.
"""
def __init__(self):
"""Initialize global Matplotlib style parameters."""
plt.rcParams.update({
"font.size": 11,
"axes.titlesize": 12,
"axes.labelsize": 11,
"xtick.labelsize": 10,
"ytick.labelsize": 10,
"legend.fontsize": 10
})
[docs]
def add_title(self, fig, text):
"""
Add a top‑level title using a dedicated invisible axis.
Parameters
----------
fig : matplotlib.figure.Figure
Figure to which the title will be added.
text : str
Title text.
Notes
-----
- A dedicated axis is added above the subplot grid.
- This avoids layout conflicts with ``suptitle()`` and ensures
consistent vertical spacing across all diagnostics figures.
"""
title_ax = fig.add_axes([0.01, 0.91, 0.98, 0.045])
title_ax.text(0, 0.5, text, fontsize=16, ha='left', va='center')
title_ax.set_axis_off()