From 687a6ef72ffbf2f89fecf26368541f7fa4b7b3a2 Mon Sep 17 00:00:00 2001 From: Jae-Joon Lee Date: Wed, 29 Aug 2012 21:50:44 +0900 Subject: [PATCH 1/2] Subplot.twin[xy] returns a Subplot instance --- lib/matplotlib/axes.py | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/lib/matplotlib/axes.py b/lib/matplotlib/axes.py index 71bf4ca86a11..d28027c8c676 100644 --- a/lib/matplotlib/axes.py +++ b/lib/matplotlib/axes.py @@ -7660,6 +7660,14 @@ def table(self, **kwargs): """ return mtable.table(self, **kwargs) + def _make_twin_axes(self, *kl, **kwargs): + """ + make a twinx axes of self. This is used for twinx and twiny. + """ + ax2 = self.figure.add_axes(self.get_position(True), *kl, **kwargs) + return ax2 + + def twinx(self): """ Call signature:: @@ -7676,8 +7684,7 @@ def twinx(self): events are only called for the artists in the top-most axes. """ - ax2 = self.figure.add_axes(self.get_position(True), sharex=self, - frameon=False) + ax2 = self._make_twin_axes(sharex=self, frameon=False) ax2.yaxis.tick_right() ax2.yaxis.set_label_position('right') ax2.yaxis.set_offset_position('right') @@ -7701,8 +7708,7 @@ def twiny(self): events are only called for the artists in the top-most axes. """ - ax2 = self.figure.add_axes(self.get_position(True), sharey=self, - frameon=False) + ax2 = self._make_twin_axes(sharey=self, frameon=False) ax2.xaxis.tick_top() ax2.xaxis.set_label_position('top') self.xaxis.tick_bottom() @@ -8874,6 +8880,13 @@ def label_outer(self): label.set_visible(firstcol) + def _make_twin_axes(self, *kl, **kwargs): + """ + make a twinx axes of self. This is used for twinx and twiny. + """ + ax2 = self.figure.add_subplot(self.get_subplotspec(), *kl, **kwargs) + return ax2 + _subplot_classes = {} def subplot_class_factory(axes_class=None): From 14e34cca43005de494bf7cb93a06ab0b5997d99e Mon Sep 17 00:00:00 2001 From: Jae-Joon Lee Date: Wed, 29 Aug 2012 23:06:49 +0900 Subject: [PATCH 2/2] updated api_changes.rst to reflect the return value change of twinx and twiny --- doc/api/api_changes.rst | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/doc/api/api_changes.rst b/doc/api/api_changes.rst index 3f3cd30f240a..64e86d03ab21 100644 --- a/doc/api/api_changes.rst +++ b/doc/api/api_changes.rst @@ -120,6 +120,10 @@ Changes in 1.2.x ``ax.transData + ax.transAxes.inverted()`` (depth is a new concept, but had it existed it would return 4 for this example). +* ``twinx`` and ``twiny`` now returns an instance of SubplotBase if + parent axes is an instance of SubplotBase. + + Changes in 1.1.x ================