3.6.14.1.2. statsmodels.graphics.utils.create_mpl_ax

statsmodels.graphics.utils.create_mpl_ax(ax=None)[source]

Helper function for when a single plot axis is needed.

Parameters:

ax : Matplotlib AxesSubplot instance, optional

If given, this subplot is used to plot in instead of a new figure being created.

Returns:

fig : Matplotlib figure instance

If ax is None, the created figure. Otherwise the figure to which ax is connected.

ax : Matplotlib AxesSubplot instance

The created axis if ax is None, otherwise the axis that was passed in.

See also

create_mpl_fig

Notes

This function imports matplotlib.pyplot, which should only be done to create (a) figure(s) with plt.figure. All other functionality exposed by the pyplot module can and should be imported directly from its Matplotlib module.

Examples

A plotting function has a keyword ax=None. Then calls:

>>> from statsmodels.graphics import utils
>>> fig, ax = utils.create_mpl_ax(ax)