environmentaltools.graphics.handle_axis
- environmentaltools.graphics.handle_axis(ax, row_plots: int = 1, col_plots: int = 1, dim: int = 2, figsize: tuple = (5, 5), projection=None, kwargs: dict = {})[source]
Create matplotlib axis for figure if needed.
Creates a new matplotlib axis/figure if none provided, supporting 2D, 3D, and projection-based plots with customizable layout.
- Parameters:
ax (matplotlib.axes.Axes) – Existing axis for the plot, or None to create new.
row_plots (int) – Number of subplot rows. Defaults to 1.
col_plots (int) – Number of subplot columns. Defaults to 1.
dim (int) – Number of dimensions (2 for 2D, 3 for 3D plots). Defaults to 2.
figsize (tuple) – Figure size as (width, height) in inches. Defaults to (5, 5).
projection – Projection type for the axis (e.g., ‘polar’, CRS objects). Defaults to None.
kwargs (dict) – Additional keyword arguments passed to plt.subplots. Defaults to {}.
- Returns:
- (fig, ax) where fig is the Figure object (or None if ax was provided)
and ax is the Axes object(s). If multiple subplots, ax is flattened array.
- Return type:
tuple