Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit c594223

Browse filesBrowse files
committed
Merge pull request #4863 from productivememberofsociety666/parasite_axes_not_pyplot
ENH: Allow "figure" kwarg for host functions in parasite_axes
2 parents 5511061 + 25105cf commit c594223
Copy full SHA for c594223

File tree

Expand file treeCollapse file tree

1 file changed

+30
-2
lines changed
Filter options
Expand file treeCollapse file tree

1 file changed

+30
-2
lines changed

‎lib/mpl_toolkits/axes_grid1/parasite_axes.py

Copy file name to clipboardExpand all lines: lib/mpl_toolkits/axes_grid1/parasite_axes.py
+30-2Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -460,20 +460,48 @@ def host_subplot_class_factory(axes_class):
460460

461461

462462
def host_axes(*args, **kwargs):
463+
"""
464+
Create axes that can act as a hosts to parasitic axes.
465+
466+
Parameters
467+
----------
468+
figure : `matplotlib.figure.Figure`
469+
Figure to which the axes will be added. Defaults to the current figure
470+
`pyplot.gcf()`.
471+
472+
*args, **kwargs :
473+
Will be passed on to the underlying ``Axes`` object creation.
474+
"""
463475
import matplotlib.pyplot as plt
464476
axes_class = kwargs.pop("axes_class", None)
465477
host_axes_class = host_axes_class_factory(axes_class)
466-
fig = plt.gcf()
478+
fig = kwargs.get("figure", None)
479+
if fig is None:
480+
fig = plt.gcf()
467481
ax = host_axes_class(fig, *args, **kwargs)
468482
fig.add_axes(ax)
469483
plt.draw_if_interactive()
470484
return ax
471485

472486
def host_subplot(*args, **kwargs):
487+
"""
488+
Create a subplot that can act as a host to parasitic axes.
489+
490+
Parameters
491+
----------
492+
figure : `matplotlib.figure.Figure`
493+
Figure to which the subplot will be added. Defaults to the current
494+
figure `pyplot.gcf()`.
495+
496+
*args, **kwargs :
497+
Will be passed on to the underlying ``Axes`` object creation.
498+
"""
473499
import matplotlib.pyplot as plt
474500
axes_class = kwargs.pop("axes_class", None)
475501
host_subplot_class = host_subplot_class_factory(axes_class)
476-
fig = plt.gcf()
502+
fig = kwargs.get("figure", None)
503+
if fig is None:
504+
fig = plt.gcf()
477505
ax = host_subplot_class(fig, *args, **kwargs)
478506
fig.add_subplot(ax)
479507
plt.draw_if_interactive()

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.