validate_plotting_kwargs#

scikitplot.api._utils.validate_plotting_kwargs(*args, ax=None, fig=None, figsize=None, nrows=1, ncols=1, index=1, **kwargs)[source]#

Validate the provided axes and figure or create new ones if needed.

This function checks if valid axes and figure objects are provided. If not, it creates new ones based on the specified parameters.

Added in version 0.3.9.

Parameters:
axmpl.axes.Axes, optional

The axes on which to plot. If None, a new one will be created.

figmpl.figure.Figure, optional

The figure in which to place the axes. If None, a new one will be created.

figsizetuple, optional

Size of the figure if a new one is created. Default is None.

nrowsint, optional

Number of rows in the subplot grid. Default is 1.

ncolsint, optional

Number of columns in the subplot grid. Default is 1.

indexint or tuple, optional

The position of the subplot on the grid. It can be: - An integer specifying the position (1-based).

*argstuple, optional

validate_plotting_kwargs properties Positional arguments passed to the function.

**kwargsdict, optional

validate_plotting_kwargs properties Keyword arguments passed to the function.

Returns:
figmpl.figure.Figure

The figure to be used for plotting.

axmpl.axes.Axes or list of mpl.axes.Axes

The axes to be used for plotting. Returns a single Axes object if only one subplot is created, or a list of Axes objects if multiple subplots are created.

Notes

The subplot position can be described by either:

  • Three integers (nrows, ncols, index)

  • The subplot will take the index position on a grid with nrows rows and ncols columns. index starts at 1 in the upper left corner and increases to the right.

Examples

Create a new figure and axes:

>>> fig, ax = validate_plotting_kwargs()

Use an existing axes:

>>> fig, ax = plt.subplots()
>>> fig, ax = validate_plotting_kwargs(ax=ax)