Skip to content

Commit 687a6ef

Browse files
committed
Subplot.twin[xy] returns a Subplot instance
1 parent 0c7cdaa commit 687a6ef

File tree

1 file changed

+17
-4
lines changed

1 file changed

+17
-4
lines changed

lib/matplotlib/axes.py

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7660,6 +7660,14 @@ def table(self, **kwargs):
76607660
"""
76617661
return mtable.table(self, **kwargs)
76627662

7663+
def _make_twin_axes(self, *kl, **kwargs):
7664+
"""
7665+
make a twinx axes of self. This is used for twinx and twiny.
7666+
"""
7667+
ax2 = self.figure.add_axes(self.get_position(True), *kl, **kwargs)
7668+
return ax2
7669+
7670+
76637671
def twinx(self):
76647672
"""
76657673
Call signature::
@@ -7676,8 +7684,7 @@ def twinx(self):
76767684
events are only called for the artists in the top-most axes.
76777685
"""
76787686

7679-
ax2 = self.figure.add_axes(self.get_position(True), sharex=self,
7680-
frameon=False)
7687+
ax2 = self._make_twin_axes(sharex=self, frameon=False)
76817688
ax2.yaxis.tick_right()
76827689
ax2.yaxis.set_label_position('right')
76837690
ax2.yaxis.set_offset_position('right')
@@ -7701,8 +7708,7 @@ def twiny(self):
77017708
events are only called for the artists in the top-most axes.
77027709
"""
77037710

7704-
ax2 = self.figure.add_axes(self.get_position(True), sharey=self,
7705-
frameon=False)
7711+
ax2 = self._make_twin_axes(sharey=self, frameon=False)
77067712
ax2.xaxis.tick_top()
77077713
ax2.xaxis.set_label_position('top')
77087714
self.xaxis.tick_bottom()
@@ -8874,6 +8880,13 @@ def label_outer(self):
88748880
label.set_visible(firstcol)
88758881

88768882

8883+
def _make_twin_axes(self, *kl, **kwargs):
8884+
"""
8885+
make a twinx axes of self. This is used for twinx and twiny.
8886+
"""
8887+
ax2 = self.figure.add_subplot(self.get_subplotspec(), *kl, **kwargs)
8888+
return ax2
8889+
88778890

88788891
_subplot_classes = {}
88798892
def subplot_class_factory(axes_class=None):

0 commit comments

Comments
 (0)