diff --git a/lib/mpl_toolkits/axes_grid1/parasite_axes.py b/lib/mpl_toolkits/axes_grid1/parasite_axes.py index 1241c93a0d67..85c5a7b05585 100644 --- a/lib/mpl_toolkits/axes_grid1/parasite_axes.py +++ b/lib/mpl_toolkits/axes_grid1/parasite_axes.py @@ -484,20 +484,48 @@ def host_subplot_class_factory(axes_class): def host_axes(*args, **kwargs): + """ + Create axes that can act as a hosts to parasitic axes. + + Parameters + ---------- + figure : `matplotlib.figure.Figure` + Figure to which the axes will be added. Defaults to the current figure + `pyplot.gcf()`. + + *args, **kwargs : + Will be passed on to the underlying ``Axes`` object creation. + """ import matplotlib.pyplot as plt axes_class = kwargs.pop("axes_class", None) host_axes_class = host_axes_class_factory(axes_class) - fig = plt.gcf() + fig = kwargs.get("figure", None) + if fig is None: + fig = plt.gcf() ax = host_axes_class(fig, *args, **kwargs) fig.add_axes(ax) plt.draw_if_interactive() return ax def host_subplot(*args, **kwargs): + """ + Create a subplot that can act as a host to parasitic axes. + + Parameters + ---------- + figure : `matplotlib.figure.Figure` + Figure to which the subplot will be added. Defaults to the current + figure `pyplot.gcf()`. + + *args, **kwargs : + Will be passed on to the underlying ``Axes`` object creation. + """ import matplotlib.pyplot as plt axes_class = kwargs.pop("axes_class", None) host_subplot_class = host_subplot_class_factory(axes_class) - fig = plt.gcf() + fig = kwargs.get("figure", None) + if fig is None: + fig = plt.gcf() ax = host_subplot_class(fig, *args, **kwargs) fig.add_subplot(ax) plt.draw_if_interactive()