slki.viz.utils ¶
This module provides utility functions for visualization in matplotlib.
Functions:
| Name | Description |
|---|---|
clear_axes | Remove ticks and disable frame and axis rendering. |
clear_axis | Remove ticks and disable frame and axis rendering. |
flat_axes | Flatten a nested list of axes into a single list. |
latex_backend | A context manager that enables LaTeX backend for matplotlib. |
plot_grid_base | Create figure and axes with default grid settings. |
savefig | Save a matplotlib figure. |
Functions¶
clear_axes ¶
Remove ticks and disable frame and axis rendering.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
| List[Axes] | List of axis to clear. | required |
clear_axis ¶
clear_axis(ax: Axes) -> None
Remove ticks and disable frame and axis rendering.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
| Axes | Single axis to clear. | required |
Source code in slki/viz/utils.py
flat_axes ¶
Flatten a nested list of axes into a single list.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
| Axes or list or tuple | The axes to flatten. | required |
Returns:
| Type | Description |
|---|---|
list[Axes] | List[matplotlib.axes.Axes]: The flattened list of axes. |
Source code in slki/viz/utils.py
latex_backend ¶
A context manager that enables LaTeX backend for matplotlib.
The LaTeX backend is enabled by updating the plt.rcParams dictionary with the necessary settings for using LaTeX with matplotlib. The original rc_params are saved and restored after the code inside the context manager is executed.
When the enable parameter is set to False, the context manager does nothing and the code inside is not affected.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
| bool | Whether to enable the LaTeX backend. Default is True. | True |
Source code in slki/viz/utils.py
plot_grid_base ¶
plot_grid_base(
rows: int,
cols: int,
*,
factor: float = 1.0,
wspace: float = 0.1,
hspace: float = 0.1,
clear_axes: bool = True,
**subplots_kwargs
) -> tuple[Figure, Axes]
Create figure and axes with default grid settings.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
| int | Number of rows of the subplot grid. | required |
| int | Number of columns of the subplot grid. | required |
| float | Figure size factor. Figure size will be | 1.0 |
| float | The amount of width reserved for space between subplots, expressed as a fraction of the average axis width. Defaults to 0.1. | 0.1 |
| float | The amount of height reserved for space between subplots, expressed as a fraction of the average axis height. Defaults to 0.1. | 0.1 |
| bool | Remove ticks and disable frame and axis rendering. Defaults to True. | True |
| Dict[str, Any] | Additional | {} |
Returns:
| Type | Description |
|---|---|
tuple[Figure, Axes] | Tuple[plt.Figure, plt.Axes]: figure, axes (non squeezed by default) |
Source code in slki/viz/utils.py
savefig ¶
savefig(
filepath_without_ext: str,
fig: Figure | None = None,
exts: list[str] | None = None,
latex_backend_exts: list[str] | None = None,
logger: Logger | None = None,
**kwargs
) -> None
Save a matplotlib figure.
This methods supports multiple file formats at once including LaTeX backend support.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
| str | The filepath without extension to save the figure. | required |
| Optional[Figure] | The matplotlib figure to save. If not provided, the current figure will be used. | None |
| List[str] | The list of file extensions to save the figure in. Default is ["png", "svg", "pdf", "pgf"]. | None |
| List[str] | The list of file extensions that require LaTeX backend. Default is ["pgf"]. | None |
| Optional[Logger] | The logger to use for logging. If not provided, the default logger will be used. | None |
| Additional keyword arguments to pass to the | {} |